Proxy not working with `stdClass`
If I try to create a proxy of a stdClass as follows
$proxyFactory = new LazyLoadingValueHolderFactory();
$initializer = function (
& $wrappedObject,
LazyLoadingInterface $proxy
) {
$proxy->setProxyInitializer(null);
$wrappedObject = (object) ['bar' => 'baz'];
return true;
};
$object = $proxyFactory->createProxy(\stdClass::class, $initializer);
$object->bar;
I get the following unexpected error: Undefined property: stdClass::$bar
Yes, dynamic properties will not work out of the box
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On Tue, Jun 20, 2017 at 12:06 PM, Marco Perone [email protected] wrote:
If I try to create a proxy of a stdClass as follows
$proxyFactory = new LazyLoadingValueHolderFactory(); $initializer = function ( & $wrappedObject, LazyLoadingInterface $proxy ) { $proxy->setProxyInitializer(null); $wrappedObject = (object) ['bar' => 'baz'];
return true;};
$object = $proxyFactory->createProxy(\stdClass::class, $initializer);
$object->bar;
I get the following unexpected error: Undefined property: stdClass::$bar
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Ocramius/ProxyManager/issues/374, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakADH0q6qc14j-LUvtSRkchYgflvsks5sF5m2gaJpZM4N_XK- .
Would it make sense to just add a note about this in the documentation of the package? And maybe provide an example on how to make dynamic properties work?
I think this needs to be fixed, rather than documented as limitation. I would suggest starting from adding .phpt files for all dynamic properties scenarios (read/write/existence) in https://github.com/Ocramius/ProxyManager/tree/e18ac876b2e4819c76349de8f78ccc8ef1554cd7/tests/language-feature-scripts
Going back at this, I think we should not implement this: dynamic properties are a problem in the language per-se.
Documentation seems to be the correct way - sorry for the confusion 3 years ago :|