Tho*_*s K 3 php reflection symfony doctrine-orm
据我所知,反射方法property_exists()在doctrine2代理对象上不起作用。
在这种情况下,将通过关系检索代理 $user->getCity()
在这种情况下,如何检查属性是否存在/已设置?
解决方法是ReflectionClass::getParentClass()。
因此,这样的代码应该可以工作:
$reflect = new \ReflectionClass($proxyObject);
if ($proxyObject instanceof \Doctrine\Common\Persistence\Proxy)
// This gets the real object, the one that the Proxy extends
$reflect = $reflect->getParentClass();
$privateProperty = $reflect->getProperty('privateProperty');
$privateProperty->setAccessible(true);
$privateProperty->setValue($proxyObject, $yourNewValue);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1901 次 |
| 最近记录: |