Skip to content

Make array access on possible false tolerant with isset#1791

Merged
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
ahmedash95:fix-bug-8068
Oct 4, 2022
Merged

Make array access on possible false tolerant with isset#1791
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
ahmedash95:fix-bug-8068

Conversation

@ahmedash95
Copy link
Copy Markdown
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
Copy Markdown
Member

Thank you!

Comment on lines -114 to -117
[
'Cannot access offset \'a\' on array{a: 1, b: 1}|(Closure(): void).',
258,
],
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

3 participants