如何解决 ForwardsCalls 特征上的 Illuminate/database 语法错误

how to solve Illuminate/database syntax error on ForwardsCalls trait

今天我更新网站时发生了这种情况。实际上我什至没有碰这个文件,但由于某种原因它显示错误并且我的网站无法加载。

问题来了

try {
        return $object->{$method}(...$parameters);
    } catch (Error | BadMethodCallException $e) { // "|" << this is the error
        $pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';

        if (! preg_match($pattern, $e->getMessage(), $matches)) {
            throw $e;
        }

        if ($matches['class'] != get_class($object) ||
            $matches['method'] != $method) {
            throw $e;
        }

        static::throwBadMethodCallException($method);
    }

我试图搜索捕获两个异常之一,但是 none。我该如何解决这个问题。我什至不知道特质。先谢谢了

来自exceptions documentation

In PHP 7.1 and later, a catch block may specify multiple exceptions using the pipe (|) character.

您正在使用较新版本 PHP 的计算机上进行开发,但在较旧版本上进行部署。你真的应该考虑在两台机器上使用完全相同的 PHP 版本以避免向后兼容性问题。

要解决您的问题,如果您的托管公司提供此类功能,您可以选择较新版本的 PHP,或者将您使用的库降级为与 PHP 兼容的版本你的主机版本。我不推荐第二种方法,降级一个包来处理过时的依赖不是一个好主意。