ProxyManager icon indicating copy to clipboard operation
ProxyManager copied to clipboard

Proxy not working with `stdClass`

Open marcosh opened this issue 8 years ago • 4 comments

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

marcosh avatar Jun 20 '17 10:06 marcosh

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- .

Ocramius avatar Jun 20 '17 10:06 Ocramius

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?

marcosh avatar Jun 20 '17 10:06 marcosh

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

Ocramius avatar Jun 20 '17 10:06 Ocramius

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 :|

Ocramius avatar Dec 20 '20 16:12 Ocramius