gpt4 book ai didi

php - 对一个教义2代理对象的反射(reflection)

转载 作者:行者123 更新时间:2023-12-01 09:31:26 25 4
gpt4 key购买 nike

据我所知,property_exists() 之类的反射方法不适用于学说 2 代理对象。

在这种情况下,代理是通过关系检索的$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);

关于php - 对一个教义2代理对象的反射(reflection),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14812123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com