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

Make array access on possible false tolerant with isset #1791

Merged
merged 3 commits into from Oct 4, 2022

Conversation

ahmedash95
Copy link
Contributor

Closes phpstan/phpstan#8068.

Hey Ondrej,

As discussed in the bug. PHP is tolerant with isset.

The removed line Cannot access offset \'a\' on array{a: 1, b: 1}|(Closure(): void). from the other test is reasonable because closure key access in isset would always be reported.

appreciate your help on getting the fix for this one.

Make array access tolerant with isset

Fixes bug phpstan/phpstan#8068
@ondrejmirtes ondrejmirtes changed the title Make array access tolerant with isset Make array access on possible false tolerant with isset Oct 4, 2022
@ondrejmirtes ondrejmirtes merged commit 20f044e into phpstan:1.8.x Oct 4, 2022
@ondrejmirtes
Copy link
Member

Thank you!

Comment on lines -114 to -117
[
'Cannot access offset \'a\' on array{a: 1, b: 1}|(Closure(): void).',
258,
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling closure or object (without ArrayAccess) causes a fatal error, so this case shouldn't be ignored.
https://3v4l.org/lFcCq

I think it might be better to have another condition to the type, whether isOffestAccessible->no throws an fatal error or not.
This might lead to improvements in issues like phpstan/phpstan#8388

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to open a new issue about this, comments on old merged PRs will get lost :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Done phpstan/phpstan#8393

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