Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[PropertyAccess] Fix accessing dynamic properties#37622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedJul 22, 2020
/cc@joelwurtz@Korbeil WDYT? On my side, I'm wondering about the perf impact of the implementation. Isn't this the same as removing the Please also add tests. |
andreyserdjuk commentedJul 22, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@nicolas-grekas it will fail when trying to access protected/private property ( |
andreyserdjuk commentedJul 23, 2020
Update: unit-test added. But only PropertyAccessor::getValue() is covered with getting dynamic value. setValue() - I didn't cover and as I see from unit-tests, the dynamic value cannot be set by design - at least setter method should be. |
joelwurtz commentedJul 29, 2020
I'm not sure about perf also, it may be slower (but need benchmark for that) Another possible implementation would be to follow@nicolas-grekas suggestion by only removing the instanceof part and add a try catch when getting the value (to catch error if property is not accessible : protected / private), maybe it would keep perf reasonable and would also allow a better error message (like property exists but is not accessible) |
andreyserdjuk commentedJul 31, 2020
@nicolas-grekas please review the last approach suggested by@joelwurtz . |
| } | ||
| }catch (\Error$e) { | ||
| if (!$ignoreInvalidProperty) { | ||
| thrownewNoSuchPropertyException(sprintf('Can\'t read protected or private property "%s" in class "%s".',$property,$class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
you can add the error in the parent exception
andreyserdjukAug 2, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I've added a previous exception as an argument, hope I've got you right.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
fabpot commentedAug 26, 2020
Thank you@andreyserdjuk. |
fabpot commentedAug 30, 2020
Reverting this PR as it breaks things by bypassing a lot of logic. One such example is when you have a class with a private property AND a __get method to access it (like TestClassMagicGet in our test suite). Before this PR, if you disable magic __get method, you will get an expected NoSuchPropertyException. But now, the property_exists() call will return true, and $object->$property will get the value because there is a __get method (which the code explicitly disallow). |
* 5.1: Revert "bug#37622 [PropertyAccess] Fix accessing dynamic properties (andreyserdjuk)"
Voetloos commentedMar 18, 2021
Issue#37615 is again an issue since this is reverted. Any update on that?@fabpot@xabbuh@nicolas-grekas |
Uh oh!
There was an error while loading.Please reload this page.