Uh oh!
There was an error while loading. Please reload this page.
fix: Anonymous class support for ReflectionHelper - #9877
Conversation
| $refClass = new ReflectionObject($obj); | ||
| if (! $refClass->hasProperty($property) && str_contains($obj::class, '@anonymous')) { |
There was a problem hiding this comment.
If you know how duplicate properties should work correctly, you can fix it here. When properties exist in both classes
michalsn
commented
Jan 9, 2026
I don't think this is a good idea. Reflection exposes class semantics as they are. Private properties belong strictly to the declaring class. Automatically scanning parent private properties would make private appear inherited, which it is not. The helper would introduce a misleading abstraction, so the current behavior should remain unchanged. |
neznaika0
commented
Jan 9, 2026
@michalsn In my opinion, if we need access to private properties, are we allowed to change the parent values? |
michalsn
commented
Jan 9, 2026
A helper should make common tasks easier, not redefine visibility rules. Parent private properties are not part of the child's API, and Reflection does not change that. |
neznaika0
commented
Jan 9, 2026
Sadly. Overdoing it again. Let's wait @paulbalandan@samsonasik Do you think it's okay to duplicate private properties in an anonymous class? The parent will not change, only the child. |
paulbalandan
commented
Jan 9, 2026
In this example: // Foo class$obj->private = 'root';
// anon class with Foo$child->private = 'child';
// helper will only change the child, the parent will contain the old value // for example, call from the root method$child->getPrivate() // rootin my opinion, |
neznaika0
commented
Jan 10, 2026
Good. This is still a problem if you really need to get a private value. Can we move it to new methods and specify it as 'feat'? |
michalsn
commented
Jan 10, 2026
I'm against this. Mocking private parent state couples tests to implementation details rather than behavior, which is generally a design smell and not something helpers should normalize. |
neznaika0
commented
Jan 12, 2026
We won't keep PR for long. Maybe someday it will be useful for a personal project. |
Description
I'm doing another PR and in the tests I found that anonymous classes cannot access parent properties. I hope this fixes it.
I want to note that there will be problems when both classes have the same properties - the reflection of the helper changes only the child. Any suggestions?
Example:
The guide, as always, corrects the translation.
Checklist: