-
Notifications
You must be signed in to change notification settings - Fork 7.8k
PHP 8.2: Issue with type declaration for iterable|object
#11797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This took me a while to dig up again but here is the rationale: |
@Girgias Thanks for the comment. IMO we should either report both or neither. If |
The thing is that The other case is not true, and this has also always been the case to allow |
@Girgias If we had type aliases, with |
I'm not sure that example is actually useful, as we currently allow redundant class types (e.g. a child class and a parent class when the child class is "obviously" redundant) when this requires resolving the type. A better example would be, what do we do with |
@Girgias Right, thanks for the explanation. I agree. We should only fail for |
Going to close then. @mpyw this should be fixed on the library side, ideally |
Description
With PHP 8.2, the following changes were applied:
As a result,
iterable
became an alias forTraversable|array
, changing the result of reflection acquisition as mentioned here.However, there's a problem. While
Traversable|object
becomes an error because it's redundant,iterable|object
compiles without any issue. But if we resolve the alias ofiterable|object
, it becomesTraversable|object|array
, which is an invalid expression for PHP's type declaration.In fact, we encountered a bug where creating a mock of a class with a method that takes
iterable|object
as an argument in the mockery/mockery causes a compile error only in PHP 8.2 or later. Should this be fixed by prohibiting the declaration ofiterable|object
itself? Or is this intended behavior, and should be addressed on the library side?PHP Version
PHP 8.2
Operating System
No response
Related Issues
The text was updated successfully, but these errors were encountered: