I came across this edge case today: https://3v4l.org/R3Q8D
Both psalm and phpstan think this code is A-OK (Once you add the requisite type hints) but it causes fatal errors way back to PHP 5.0.0
I believe classes should be able to access protected properties on their siblings if the property in question was declared by a shared parent, but it seems both the engine and reflection (ie. getDeclaringClass) think that redeclaring a protected property makes it a property of the child, not the parent.
This is particularly confusing since the parent class *can* access the child class' redeclared protected property, only the sibling can't.
Properties were invariant until the introduction of property hooks, so the only edge cases I can think of would be in property hooks (But when the input is correctly typed this shouldn't be a problem either)
Is there a technical reason for this behavior or would it be possible to relax this?
- Jonathan