symfony / symfony

The Symfony PHP framework
https://symfony.com
MIT License
29.64k stars 9.43k forks source link

[PropertyInfo] PhpStanExtractor can't get type for private property from parent #58338

Open etshy opened 2 hours ago

etshy commented 2 hours ago

Symfony version(s) affected

6.4.9

Description

On the case of a private property from a parent class, PhpStanExtractor can't get types from the property evenbt though a comment on the getDocBlackFromProperty says // Use a ReflectionProperty instead of $class to get the parent class if applicable

The line $reflectionProperty = new \ReflectionProperty($class, $property); will trhow an Exception saying the property doesn't exists and the method will simply return null

Looking at the code on 7.2 branch this should allso happen in 7.2.

How to reproduce

3v4l reproducer about the ReflectionProperty throwing an exception : https://3v4l.org/MtHKU

If needed i'll make a reproducer repo as soon as I can

Possible Solution

On the catch:

Though it's adding Reflection call so maybe it was intended to not do that from the start for performance ?

Additional Context

No response

alexandre-daubois commented 2 hours ago

Private properties are not accessible in child classes. Only protected properties are.

In your example, if you want to access to B::$a, you have to declare A::$a as protected, not private.