Closed phil-davis closed 2 years ago
https://github.com/sabre-io/Baikal/actions/runs/3211896895/jobs/5250379047
Error: Return type mixed of method Flake\Core\Datastructure\ChainLink::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess::offsetGet().
Error: Return type mixed of method Flake\Core\Datastructure\ChainLink::current() is not covariant with tentative return type mixed of method Iterator::current().
Error: Return type mixed of method Flake\Core\Datastructure\ChainLink::key() is not covariant with tentative return type mixed of method Iterator::key().
------ -----------------------------------------------------------------------
Line Core/Frameworks/Flake/Core/Datastructure/ChainLink.php
------ -----------------------------------------------------------------------
63 Return type mixed of method
Flake\Core\Datastructure\ChainLink::offsetGet() is not covariant with
tentative return type mixed of method ArrayAccess::offsetGet().
💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute
to temporarily suppress the error.
77 Return type mixed of method
Flake\Core\Datastructure\ChainLink::current() is not covariant with
tentative return type mixed of method Iterator::current().
💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute
to temporarily suppress the error.
81 Return type mixed of method Flake\Core\Datastructure\ChainLink::key()
is not covariant with tentative return type mixed of method
Iterator::key().
💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute
to temporarily suppress the error.
------ -----------------------------------------------------------------------
Error: [ERROR] Found 3 errors
I will have at look - these are new complaints by phpstan
when running PHP 8.1. I get them locally when I switch to PHP 8.1.
Thanks!
In PHP 8.1,
ArrayAccess
has return types specified for methods likeoffsetGet
and so if a class extendsArrayAccess
then it now needs to specify the return type (in this casemixed
).But the
mixed
return type is only available form PHP 8.0 onward. So we can't write that because we still support PHP 7.2 7.3 7.4.So we have to add https://php.watch/versions/8.1/internal-method-return-types#ReturnTypeWillChange and that suppresses the deprecation notice that PHP 8.1 emits. After PHP 7 is dropped (in the future) then we need to explicitly mention the return type.