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

offsetAccess.nonOffsetAccessible suppressed by isset #10926

Closed
robchett opened this issue Apr 24, 2024 · 4 comments · Fixed by phpstan/phpstan-src#3045
Closed

offsetAccess.nonOffsetAccessible suppressed by isset #10926

robchett opened this issue Apr 24, 2024 · 4 comments · Fixed by phpstan/phpstan-src#3045

Comments

@robchett
Copy link

Bug report

Error exception is raised but no warning from SA.

Code snippet that reproduces the problem

https://phpstan.org/r/4ade25a7-da2a-40ae-b3e3-89713d804052

Expected output

Cannot access offset 'a' on stdClass.

Did PHPStan help you today? Did it make you happy in any way?

No response

@ondrejmirtes
Copy link
Member

/cc @rajyan You've touched this last in phpstan/phpstan-src#1174. Can you please look into this? Array access on stdClass even in isset() leads to fatal error: https://3v4l.org/GVD8v

@rajyan
Copy link
Contributor

rajyan commented May 2, 2024

I think it's related to
#8393

but not sure enough why stdClass is not isOffsetAccessible->no.

@rajyan
Copy link
Contributor

rajyan commented May 2, 2024

but not sure enough why stdClass is not isOffsetAccessible->no.

it's because stdClass is not final.
https://github.com/rajyan/phpstan-src/blob/c792050e6830a139ae746cff4b534573dfe8476a/src/Type/ObjectType.php#L1089-L1091

simply changing this line as

if ($classReflection->isFinal() || $classReflection->getName() === 'stdClass') {

can fix this issue, but haven't fully considered whether this is the right way.

@rajyan
Copy link
Contributor

rajyan commented May 2, 2024

haven't fully considered whether this is the right way.

phpstan/phpstan-src@b55656f

we can create a class that implements ArrayAccess and extends stdClass at the same time.

https://3v4l.org/5nStL

so, we need to find a good compromise for the conditions for arrayOffsetAccessible that currently depends on ’final’.

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

Successfully merging a pull request may close this issue.

3 participants