Closed lisachenko closed 5 years ago
This was quick! Thank you for your hard work! 🍺
With this PR, my code to set private's property value from an aspect works now:
$setter = \Closure::bind(function ($object, $value) use ($field) {
$object->$field = $value;
}, null, \get_parent_class($fieldAccess->getThis()));
$setter($fieldAccess->getThis(), 'some value');
Not sure if you expect the below code to work as well ('cause it doesn't):
$fieldAccess->getField()->setAccessible(true);
$fieldAccess->getField()->setValue($fieldAccess->getThis(), 'some value');
The inspection completed: 1 updated code elements
@lisachenko any plans to release this feature? :)
3.0.0-RC1 is ready to test, if it is ok, then 3.0.0 will be released soon
This PR introduces an ability to intercept access to private properties in classes. We use closure binding in generated proxy child class and bind it to the parent scope so we gain a control over private properties of the class as well.
Here is an example of generated constructor for the
Demo\Example\PropertyDemo
proxy class:As we store references to properties from given original object instance, we can read and write them via aspects without additional code logic.
Feature was requested in #411 by @jakzal