序列化 PHP 反射 [英] Serialized PHP Reflection

查看:41
本文介绍了序列化 PHP 反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下示例代码:

<?php

class a {
    function b() {}
}

$r=new ReflectionMethod(new a, "b");
var_dump($r->getParameters());
$s=serialize($r);
$r=unserialize($s);
var_dump($r->getParameters());

?>

产生以下输出:

array(0) { }
Fatal error: ReflectionFunctionAbstract::getParameters() [<a href='reflectionfunctionabstract.getparameters'>reflectionfunctionabstract.getparameters</a>]: Internal error: Failed to retrieve the reflection object in [...]test.php on line 13

问题是,有没有办法在 PHP 中正确序列化/反序列化 Reflection 对象?

The question stands, is there a way to correctly serialize/unserialize Reflection objects in PHP?

谢谢.

推荐答案

来自 http://bugs.php.net/bug.php?id=30324

序列化不适用于虚拟属性和这个问题通常发生在内部类中.

Serialization doesn't work on virtual properties and this problem usually occurs with internal classes.

也许这种方法就是这种情况.但是,我不确定文档不清楚.http://in3.php.net/manual/en/reflectionfunctionabstract.getparameters.php

Maybe that is the case with this method. However, I'm not sure the documentation is not clear. http://in3.php.net/manual/en/reflectionfunctionabstract.getparameters.php

这篇关于序列化 PHP 反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆