如何修复错误解析错误:语法错误,Cell.php中出现意外的“=”

ruarlubt  于 2023-03-22  发布在  PHP
关注(0)|答案(2)|浏览(216)

我已经部署了我的laravel源代码,其中集成了maatwebsite包,我在我的项目中有一些导出excel。它在xampp localhost中工作正常,但当我将其部署到虚拟服务器时,它总是返回错误:

message: "Parse error: syntax error, unexpected '='"
exception: "Symfony\Component\Debug\Exception\FatalThrowableError"
file: "/var/www/src/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php"
line: 517

我设置了php7.1和我的require composer.json:

"require": {
        "php": ">=7.0.0",
        "ext-json": "*",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "^5.4.0",
        "maatwebsite/excel": "^3.1"
    }

有人能告诉我如何解决这个问题吗???

mccptt67

mccptt671#

不要在composer中使用=,你应该使用^~
完整的解释在波浪符版本范围(~)和脱字符版本范围(^)
~运算符最好通过以下示例来解释:~1.2等价于〉=1.2〈2.0.0,而~1.2.3等价于〉=1.2.3〈1.3.0。正如你所看到的,它主要用于尊重语义版本的项目。
^操作符的行为非常相似,但它更接近语义版本控制,并且总是允许非破坏性更新。例如^1.2.3相当于〉=1.2.3〈2.0.0,因为2.0之前的版本都不应该破坏向后兼容性。对于1.0之前的版本,它也考虑到安全性,将^0.3视为〉=0.3.0〈0.4.0。

dhxwm5r4

dhxwm5r42#

编辑cell.php文件,在我的例子中路径是vendor/phpoffice/phpspreadsheet/src/phpspreadsheet/Cell/Cell.php,因为我使用composer安装和搜索这个函数

public function setValue($value, ?IValueBinder $binder = null): self
    {
        $binder ??= self::getValueBinder();
        if (!$binder->bindValue($this, $value)) {
            throw new Exception('Value could not be bound to cell.');
        }

        return $this;
    }

在此行中删除'??' $binder??= self::getValueBinder();到
$binder = self::getValueBinder();
这工作对我来说,再见

相关问题