Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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=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.

like image 459
Dennis Kreminsky Avatar asked May 29 '11 15:05

Dennis Kreminsky


People also ask

Why do we serialize PHP?

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.

What is PHP reflection?

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.

How can I serialize data in PHP?

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.

Which two functions are used for serialization in PHP?

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);


1 Answers

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

like image 70
Mridul Kashatria Avatar answered Sep 20 '22 04:09

Mridul Kashatria