You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you write code which relys on reflection behavior, you should guard it against possible changing data.
IMO In case you write code which expects a certain structure, you could even already hardcode against the real class you are reflecting against…
The whole point of reflection is that you don’t know/assume the structure beforehand, therefore you need to be defensive
The use case is to convert an object from a parent class to a child class. The parent class contains a lot of arguments in the constructor, and also contains some properties that are not in the constructor.
The child class add a few new parameters in the constructor.
I prefer not to write all the parameters of the constructor manually (in the method "fromHelloWorld" in the example) as there are a lot, so I used ReflectionMethod.
I had a talk with ondrej about this and he shares my opinion.
as soon as you are using reflection you are crossing a line in which you cannot/should not expect static analysis to support your code anymore (by design)
Activity
[-]Support ReflectionMethod[/-][+]Support ReflectionMethod + getParameters[/+]staabm commentedon May 30, 2026
I am not sure the suggestion is useful.
If you write code which relys on reflection behavior, you should guard it against possible changing data.
IMO In case you write code which expects a certain structure, you could even already hardcode against the real class you are reflecting against…
The whole point of reflection is that you don’t know/assume the structure beforehand, therefore you need to be defensive
wdyt?
momala454 commentedon Jun 1, 2026
The use case is to convert an object from a parent class to a child class. The parent class contains a lot of arguments in the constructor, and also contains some properties that are not in the constructor.
The child class add a few new parameters in the constructor.
I prefer not to write all the parameters of the constructor manually (in the method "fromHelloWorld" in the example) as there are a lot, so I used ReflectionMethod.
Example: https://phpstan.org/r/1dd57bc2-8d19-4f48-b095-6162dd2d435e
Infer parameter names from ReflectionMethod::getParameters()
staabm commentedon Jun 4, 2026
I had a talk with ondrej about this and he shares my opinion.
as soon as you are using reflection you are crossing a line in which you cannot/should not expect static analysis to support your code anymore (by design)
github-actions commentedon Jul 6, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.