开发者

Serialized PHP Reflection

Please consider the following example code:

<?php

class a {
    function b() {}
}

$r=new ReflectionMethod(new a, "b");
var_dump($r->getParameters());
$s=seria开发者_开发百科lize($r);
$r=unserialize($s);
var_dump($r->getParameters());

?>

That produces the following output:

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

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

Thank you.


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

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

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


Use the JMS Serializer to serialize private and protected properties and also virtual properties using methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜