Please consider the following example code:
<?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());
?>
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.
Definition and Usage The serialize() function converts a storable representation of a value. To serialize data means to convert a value to a sequence of bits, so that it can be stored in a file, a memory buffer, or transmitted across a network.
The term “reflection” in software development means that a program knows its own structure at runtime and can also modify it. This capability is also referred to as “introspection”. In the PHP area, reflection is used to ensure type safety in the program code.
To get the POST values from serializeArray in PHP, use the serializeArray() method. The serializeArray( ) method serializes all forms and form elements like the . serialize() method but returns a JSON data structure for you to work with.
Serialization in PHP is mostly automatic—it requires little extra work from you, beyond calling the serialize( ) and unserialize( ) functions: $encoded = serialize(something); $something = unserialize(encoded);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With