DDC-1434: __load method on Proxy classes is not triggered when using class metadata reflection #1798

Closed
opened 2026-01-22 13:26:19 +01:00 by admin · 4 comments
Owner

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: $foo is a proxy class instance of a managed entity with a property bar (with getter), that has value asd:

$meta = $em->getClassMetaData('Foo');
$meta->setFieldValue($foo, 'bar', 'foobar');
var_dump($foo->getBar()); // asd

If 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

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: `$foo` is a proxy class instance of a managed entity with a property `bar` (with getter), that has value `asd`: `$meta = $em->getClassMetaData('Foo');` `$meta->setFieldValue($foo, 'bar', 'foobar');` `var_dump($foo->getBar()); // asd` If 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`
admin added the Bug label 2026-01-22 13:26:19 +01:00
admin closed this issue 2026-01-22 13:26:20 +01:00
Author
Owner

@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): 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?
Author
Owner

@doctrinebot commented on GitHub (Oct 18, 2011):

Issue was closed with resolution "Can't Fix"

@doctrinebot commented on GitHub (Oct 18, 2011): Issue was closed with resolution "Can't Fix"
Author
Owner

@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 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);`
Author
Owner

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

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1798