在此示例中,我还记得会话中的ReflectionProperty实例。
class Test
{
public $Field;
}
$prop;
session_start();
if (!isset($_SESSION['prop']))
{
$ref = new ReflectionClass('Test');
$prop = $ref->getProperties(ReflectionProperty::IS_PUBLIC);
$_SESSION['prop'] = $prop;
}
else
{
$prop = $_SESSION['prop'];
}
$t = new Test();
$prop[0]->setValue($t, 1);
var_dump($t);
第一次运行可以,脚本将值设置为field。当我在会话中使用经过重命名的实例时,第二次运行脚本失败。
我有消息:未捕获的错误:内部错误:无法在...中检索反射对象
为什么我不能使用记住的ReflectionProperty实例?