mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-1434: __load method on Proxy classes is not triggered when using class metadata reflection #1798
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Oct 18, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user pkruithof:
I'm using reflection to set fields on an object. These values are not set on managed entities.
Example:
$foois a proxy class instance of a managed entity with a propertybar(with getter), that has valueasd:$meta = $em->getClassMetaData('Foo');$meta->setFieldValue($foo, 'bar', 'foobar');var_dump($foo->getBar()); // asdIf I manually trigger the load method, this works:
$foo; // FooProxy instance$foo->**load();$meta = $em->getClassMetaData('Foo');$meta->setFieldValue($foo, 'bar', 'foobar');var_dump($foo->getBar()); // foobar@doctrinebot commented on GitHub (Oct 18, 2011):
Comment created by @beberlei:
This is not fixable as there is no hook for this in PHP to let us know that someone attempts this. Using reflection to get values breaks OOP anyways, so layers that are nearer to the user than the entities should not be allowed to do this.
Wher ein Symfony does this happen for you?
@doctrinebot commented on GitHub (Oct 18, 2011):
Issue was closed with resolution "Can't Fix"
@doctrinebot commented on GitHub (Oct 18, 2011):
Comment created by pkruithof:
This is my own code, not part of Symfony. I thought it might help to indicate that I'm using Doctrine as part of a Symfony project.
The reason I'm using reflection is because I want to dynamically set values to entities. I'm not too familiar with Doctrine's inner workings, but if the metadata class supports reflection, I don't understand why I should not use it. But I suppose I could also use
$obj->$setter($value);@doctrinebot commented on GitHub (Oct 18, 2011):
Comment created by @beberlei:
well the doctrine code internally uses guard clauses so that this doesnt happen. You can check for "instanceof Proxy" yourself and initialize it if neecessary. However i would really recommend using the getters/setters.