Skip to content
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

Fix false positives for array accesses on iterable #891

Closed

Conversation

julienfalque
Copy link

No description provided.

Given a property with native type `iterable` and PHPDoc type that
allows array access, e.g. `array|(ArrayAccess&iterable)`, reading or
writing to this property using array access was reported as an error.
@ondrejmirtes
Copy link
Member

Nope, sorry, the original behaviour is intended. Bar[] + iterable is still iterable, not array.

iterable means Traversable|array, the array access is not guaranteed.

@julienfalque
Copy link
Author

I don't understand. In the following example:

/** @var array|(ArrayAccess&iterable) $foo
private iterable $foo;

isn't the PHPDoc type supposed to "extend" the native type? Both array and ArrayAccess&iterable are subtypes of iterable, why not use the PHPDoc type as-is in this case?

@ondrejmirtes
Copy link
Member

Please open an issue, right now I don't know what problem you're trying to fix :)

@julienfalque
Copy link
Author

See phpstan/phpstan#6243.

@herndlm
Copy link
Contributor

herndlm commented Dec 27, 2021

ArrayAccess might need some special care here and there. Especially in an intersection type. Your phpstan/phpstan#6184 is another example, which I tried to work on, but failed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants