Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

patriknemecek's avatar

Laravel 5.6: Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)

Hello, when I was solve problem with TrustedProxies, I got another error 500 with error message:

local.ERROR: Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) at vendor/symfony/routing/Route.php:53).

Before upgrade all works fine.

0 likes
17 replies
Snapey's avatar

did the 'upgrade' also significantly change the Laravel version?

Snapey's avatar

yes, 5.6 now, but what was it before? Your error is typical of an incompatible php version

patriknemecek's avatar

I use PHP 7.2.2, Laravel 5.6 requires PHP 7.1.3 or higher.

patriknemecek's avatar

Yes, it is probably problem with PHP, now I tried fresh Laravel install and same error.

Snapey's avatar
Snapey
Best Answer
Level 122

create a simple test.php page in your public folder

put phpinfo() in it and then hit test.php in your browser

Sometimes the php version being used by the webserver can be a different version to the command line

10 likes
patriknemecek's avatar

Yes you are absolutely right, I didn't thought my Apache2 use PHP 7.0

Sandburg2011's avatar

Can someone please explain how to update the Apache php version to 7.2?

HafizSaifullah's avatar

I solved the above problem by disabling 7.0 and enabling 7.2 just like in the below link

2 likes
danielme's avatar

Had the same issue, forgot to disable php 7.0 before enabling 7.2 module in apache (nothing changes in apache and no errors are given if you just enable 7.2 without disabling 7.0 first).

Apache: "sudo a2dismod php7.0" "sudo a2enmod php7.2" "sudo service apache2 restart"

Also handy if you are on Ubuntu/Debian: "update-alternatives --config php" lets you set the default php version for CLI, this way you can jump back and forth between php versions to use as default.

Here is a nice guide with a lot of info you need regarding php versions and apache: https://thishosting.rocks/install-php-on-ubuntu/

1 like
debbiev's avatar

If you have shell access, check out your $PATH. Mine was picking up an old version of php.

whereis php echo $PATH

I found the right version of php here: /opt/php71/bin

so I add this line to the end of my .bashrc

export PATH=/opt/php71/bin:$PATH

Now composer doesn't error. and php artisan runs great!

:-D

PS. The version of php that you're using in the shell may be different from the version used to serve your site. That can be fixed in cpanel's php selector.

Avinash57's avatar

I am using ""Laravel Framework Lumen (5.6.4) (Laravel Components 5.6.*)"" with php version 7.2.2 in MAMP and in terminal both.

but still getting the similar error :

""Parse error: parse error, expecting '&'' or"variable (T_VARIABLE)"' in /vendor/illuminate/support/helpers.php on line 554"".

Please suggest any solution.

knolskape's avatar

Hi, Facing same issue despite that I have same version of php 7.1.5 on both CLI and apache server.Iam using laravel 5.4.Iam .Any suggestions will help.

aduxia's avatar

Hello,

I have the same problem and I think it's a php version incompatibility between the composer version and the server version.

In my composer I have php 7.1 version and my server has 5.6 php version. When I change the server version to 7.1, delete the composer.lock, delete the vendor directory and regenerate the vendor, all starts to work another time.

best regards

Please or to participate in this conversation.