Symfony 5.2.3 接口类型提示

Symfony 5.2.3 interface type-hinting

自从我更新了 composer.json(我刚从 symfonyconsoledotenvframework-bundleyaml 版本切换到 "5.0.* to,"5.2.*), 我有这个错误:

syntax error, unexpected '|', expecting variable (T_VARIABLE) 来自第 27 行,文件 vendor/psr/link/src/EvolvableLinkInterface.php.

(public function withHref(string|\Stringable $href);)

我决定删除我的一个兼性参数类型提示(例如 \Stringable)并且效果很好。

我 运行 在 PHP 7.4.15 下。

你知道我该如何解决吗?

看来我们https://github.com/php-fig jumped the gun with using Union Type Hints的好哥们只有php8才有。他们没有为 php7 提供支持。由于某种原因,他们从 php5 变成了 php8。你可以在 packagist 中看到这个:

psr/link v1.0.0 vs psr/link v1.1.0

也在:

psr/log v1.1.4 vs psr/log v2.0.0

这也在依赖于 psr/log 和 运行 php7.

的 Laravel 7 中引起了问题

您需要指定较旧的软件包版本:

composer require psr/link "1.0.*"

composer require psr/log "^1.0"