Laravel5.x在PHP版本7.0

@爱耍流氓的唐僧  June 21, 2021

laravel版本5.x在PHP版本7.0情况下会报错,如下:

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

那个问号在那里指定了一个可为空的类型。这是 PHP 7.1 中引入的功能。很可能您的服务器正在运行旧版本的 PHP

主要是PHP7.1的一些新特性导致的,解决办法如下:

Delete vendor folder
Delete composer.lock file
Add this to composer.json file under config

"platform": {
   "php": "7.0.0"
}
As well, ensure PHP version under require is set to 7.0.0 as shown below in config.platform.php:

    "config": {
        "platform": {
            "php": "7.0.0"
        }
     }
Run composer install using CMD

添加新评论