Skip to content

Conversation

JeroenVanOort
Copy link
Contributor

It occurred to me that native properties were not taken in account on universal object crates. This fixes that.

@ondrejmirtes
Copy link
Member

For native properties this extension isn’t executed at all.

@JeroenVanOort
Copy link
Contributor Author

I'm inclined agree with you and I have probably been fixing something that doesn't need fixing while not fully understanding what I'm doing, but if you are right, why did my work require changes in tests/PHPStan/Analyser/AnalyserIntegrationTest.php?

And why wouldn't we want https://github.com/phpstan/phpstan-src/blob/master/tests/PHPStan/Analyser/data/universal-object-crate.php#L36 to be reported?

@ondrejmirtes
Copy link
Member

It's complicated. The error on that line should not be reported because the property is private and isn't accessible from the outside. So for the outside caller it doesn't have the type string.

We cannot make any assumptions how __get/__set are implemented in classes registered in UniversalObjectCratesClassReflectionExtension. It'd be wrong to jump to conclusion that the type returned by the __get method is the same as the one of the private property with the same name.

What your modification basically did is making all private properties public in universalObjectCrateClasses, which isn't correct.

@JeroenVanOort
Copy link
Contributor Author

I understand now. Thanks for explaining.

@ondrejmirtes
Copy link
Member

But you could update this extension with this logic:

  • hasProperty() should return false for subclasses of stdClass that already have the native property with the same name.
@ondrejmirtes
Copy link
Member

That way the line 36 will report access to undefined property which is the actual behaviour.

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

Labels

None yet

2 participants