首页 > 解决方案 > 新的 Laravel install v 5.4 index.php 抛出解析错误。PHP 7.2.10-0ubuntu0.18.04.1

问题描述

在 Ubuntu 的 Digital Ocean 上安装新的 Laravel。当前的 PHP 安装。Apache2 可以很好地访问 Php,因为我添加了几行代码来吐出错误。这是输出:

解析错误:语法错误,第 388 行 /var/www/html/blog/vendor/laravel/framework/src/Illuminate/Support/Arr.php 中的意外“=”

    public static function pluck($array, $value, $key = null)
{
    $results = [];
    [$value, $key] = static::explodePluckParameters($value, $key);
    foreach ($array as $item) {
        $itemValue = data_get($item, $value);
        // If the key is "null", we will just append the value to the array and keep
        // looping. Otherwise we will key the array using the value of the key we
        // received from the developer. Then we'll return the final array form.
        if (is_null($key)) {
            $results[] = $itemValue;
        } else {
            $itemKey = data_get($item, $key);
            if (is_object($itemKey) && method_exists($itemKey, '__toString')) {
                $itemKey = (string) $itemKey;
            }
            $results[$itemKey] = $itemValue;
        }
    }
    return $results;
}

第 888 行是:

[$value, $key] = static::explodePluckParameters($value, $key);

Laravel 在使用“laravel new(站点名称)”创建新站点时会自动创建一个密钥

服务器运行我的其他网站就好了。我已经完成了几次干净的 Laravel 安装,同样的问题。

标签: phplaravelapache2

解决方案


发生这种情况是因为评估此脚本的 PHP 不是 7.2 版。它是低于 7.1 的版本。7.1 中引入了数组解构赋值 - https://wiki.php.net/rfc/short_list_syntax

您需要弄清楚安装了哪些 PHP 版本以及执行代码的确切版本。


推荐阅读