tako's avatar
Level 1

syntax error, unexpected '|', expecting variable (T_VARIABLE)

I have an issue to make an async HTTP request with larevel 8.11.2 and php 7.4.11

  public function index()
    {
        $result = response()->json(Product::orderByDesc('updated_at')->get(), 200);
        return Http::async()->get()->then(
            fn (Response|TransferException $result) => $this->handleResult($result)
        ));
    }

When I save the file it displays this error :

syntax error, unexpected '|', expecting variable (T_VARIABLE)

By they way, I don't know if it's the right way to add the result in the response.

0 likes
5 replies
Sinnbeck's avatar

Which version of php are you running?

1 like
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@tako Then you cant use this Response|TransferException $result. It wasnt introduced until 8.0

1 like
oka_'s avatar

@Sinnbeck i have the same problem, the error is on function.php in my laravel:

function renderUsing(OutputInterface|null $renderer): void{
	...
}

So, how should I change it?

Sinnbeck's avatar

@oka_ Make it optional you mean?

function renderUsing(?OutputInterface $renderer = null): void{
	...
}
1 like

Please or to participate in this conversation.