Laravel:PHP 解析错误:语法错误,意外的“?” 在第 500 行的 /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53748977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:12:45  来源:igfitidea点击:

Laravel: PHP Parse error: syntax error, unexpected '?' in /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500

phplaravelubuntu

提问by Ricardo Santos

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

由于我将我的 php 版本从 5.6 升级到 7.2,我的 php_errors.log 上有一个持久性错误: PHP Parse error: syntax error, unexpected '?' in /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500

On Line 500:

在第 500 行:

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

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.

我在stackoverflow上搜索这个,主要原因是服务器仍在使用php5.6,但我认为这不是原因。平台是 Laravel 5.7,显然一切正常。

If i run php -vfrom the terminal i got PHP 7.2:

如果我php -v从终端运行,我会得到 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

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:

stackoverflow上的一些问题建议添加一个phpinfo来显示系统使用的php版本,其实是正确的:

php info from my platform

来自我平台的 php 信息

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

即使我试图禁用旧版本,服务器也说 php5.6 已经被禁用:

Module php5.6 already disabled

Module php5.6 already disabled

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

禁用 php5.6 并启动并运行 php 7.2,这可能是什么原因造成的?

Thanks in advance.

提前致谢。

采纳答案by Ricardo Santos

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

正如@MonkeyZeus 所建议的那样,通过服务器重启解决了问题。显然,在升级 PHP 和 Laravel 后,某些事情并没有增加。

回答by Pawan Kumar

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

出现这个问题是因为你的版本路径还是5.6 设置为7.2

//SWITCHING between PHP versions

//在PHP版本之间切换

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

须藤更新替代品 --set php /usr/bin/php5.6

须藤更新替代品 --set phar /usr/bin/phar5.6

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

须藤 a2dismod php7.2

须藤 a2enmod php5.6

//Switch into php 7.2

//切换到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

须藤更新替代品 --set php /usr/bin/php7.2

须藤更新替代品 --set phar /usr/bin/phar7.2

须藤更新替代品 --set phar.phar /usr/bin/phar.phar7.2

须藤 a2dismod php5.6

须藤 a2enmod php7.2