I installed a fresh Symfony v5.3, ApiPlatform v2.6.6. When I enter to /api
url I'm getting that error:
Fatal error: Declaration of Fig\Link\Link::withHref(Stringable|string $href):
Symfony\Component\ErrorHandler\DebugClassLoader must be compatible with
Psr\Link\EvolvableLinkInterface::withHref($href) in
/api-platform-course/vendor/fig/link-util/src/Link.php on line 22
I opened that file with editor: vendor/fig/link-util/src/EvolvableLinkTrait.php
and it is implementing that interface: Psr\Link\EvolvableLinkInterface
. It seems this trait isn't correctly implementing methods. For example interface's method is this:
public function withHref(string|\Stringable $href);
EvolvableLinkTrait::withHref
method implementation is this:
public function withHref(\Stringable|string $href): static
As you can see original method hasn't static
keyword but implementation has. I removed the static
return type hint from implementation but I'm getting same error still. Then I removed all type hints from implementation and error is gone. My current implementation is that:
public function withHref($href)
Everything fine for this method. Other methods has same problem too and I fixed with same way (withRel()
, withoutRel()
, withAttribute()
, withoutAttribute()
methods).
I'm using PHP 8.0 and Nginx server. What do you offer for this problem? Must I change package versions or lower Symfony version or anything else? Thanks.
It looks like
fig/link-util
may need to update the package constraints.fig/link-util:1.2.0
is type hinted which means its should have"psr/link": "^2.0.0"
as a required package not"psr/link": "^1.1.0 | ^2.0.0"
it also says it provides a 1.0 psr/link-implementation but that should say 2.0.