4

Since i upgraded my php version from 5.6 to 7.2, i have a persistant error on my php_errors.log: PHP Parse error: syntax error, unexpected '?' in /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500

On Line 500:

return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ?? null);

I Search for this on stackoverflow, and the main cause is server still using php5.6, but i think it's not the reason. Platform is Laravel 5.7 and apparently is all working fine.

If i run php -v from the terminal i got PHP 7.2:

PHP 7.2.12-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 12 2018 09:55:12)(NTS) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.12-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Some questions on stackoverflow suggest adding a phpinfo to show the php version used by the system, and actually is the correct:

php info from my platform

Even if i tried to disable old version, server says that php5.6 is already disabled:

Module php5.6 already disabled

With php5.6 disabled and php 7.2 up and running, what could be causing this ?

Thanks in advance.

Ricardo Santos
  • 81
  • 1
  • 2
  • 12
  • What is on line #499, #500, and #501? – MonkeyZeus Dec 12 '18 at 18:13
  • 1
    Line 500 seems to be `return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ?? null);`, which should work in 7.2. I'm not sure where you're running phpinfo from, but try creating the file within the public directory and browse to it, just in case it's running from a different ini. – aynber Dec 12 '18 at 18:15
  • Yeah, I'd put the `phpinfo()` call in Laravel's `public/index.php` to make sure *Laravel* is getting PHP 7.2. The error message you're getting is exactly what older PHP versions would say when encountering modern Laravel. – ceejayoz Dec 12 '18 at 18:16
  • Did you update Laravel at the same time? The null coalescing operator `??` is only supported in PHP >= 7 so if you've always been running that Laravel version then PHP 5.6 should have been throwing that error this whole time. – MonkeyZeus Dec 12 '18 at 18:17
  • 1
    are you using mod_php? did you restart Apache after switching to 7.2? – Joni Dec 12 '18 at 18:19
  • @MonkeyZeus yes, i upgraded Laravel at same time. Currently running Laravel 5.7. – Ricardo Santos Dec 12 '18 at 18:20
  • 1. You should restart your nginx/apache as Joni said. 2. You should find line about php socket in nginx/apache config and rewrite it for new php version. – IndianCoding Dec 12 '18 at 18:21
  • @ceejayoz did it, and phpinfo shows php 7.2 :| – Ricardo Santos Dec 12 '18 at 18:22
  • 3
    Try restarting your web server. Something is not adding up... – MonkeyZeus Dec 12 '18 at 18:22
  • @Joni on phpinfo i have on loaded modules: mod_php7 (and many others) and yes, i restart apache2. – Ricardo Santos Dec 12 '18 at 18:24
  • @MonkeyZeus it works. I was trying to avoid a reboot since is the production server (I did the same on a DEV server and everything was fine without reboot). – Ricardo Santos Dec 12 '18 at 18:30

2 Answers2

7

This problem occurs because your version path is still 5.6 set it 7.2

//SWITCHING between PHP versions

sudo update-alternatives --set php /usr/bin/php5.6

sudo update-alternatives --set phar /usr/bin/phar5.6

sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6

sudo a2dismod php7.2

sudo a2enmod php5.6

//Switch into php 7.2

sudo update-alternatives --set php /usr/bin/php7.2

sudo update-alternatives --set phar /usr/bin/phar7.2

sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2

sudo a2dismod php5.6

sudo a2enmod php7.2

Gufran Hasan
  • 8,910
  • 7
  • 38
  • 51
Pawan Kumar
  • 734
  • 9
  • 14
0

Problem solved with a server reboot, as suggested by @MonkeyZeus. Apparently something was not adding up after upgrade both PHP and Laravel.

Ricardo Santos
  • 81
  • 1
  • 2
  • 12