Bug #70719 [Opn->Ver]: ReflectionParameter + serialize()

From: Date: Thu, 15 Oct 2015 13:18:24 +0000
Subject: Bug #70719 [Opn->Ver]: ReflectionParameter + serialize()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196624@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70719&edit=1 ID: 70719 Updated by: ab@php.net Reported by: andreas at dqxtech dot net Summary: ReflectionParameter + serialize() -Status: Open +Status: Verified Type: Bug Package: Reflection related Operating System: Linux PHP Version: irrelevant Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2015-10-15 12:21:56] andreas at dqxtech dot net Description: ------------ Trying to serialize a ReflectionMethod object raises a warning. Trying to serialize and unserialize a ReflectionParameter is ok, but then ::isOptional() on the unserialized reflection parameter causes a fatal error. https://3v4l.org/t1bCc Fatal error: ReflectionParameter::isOptional(): Internal error: Failed to retrieve the reflection object The minimum fix (without major behavior change) would be to make the error message more meaningful, and mention that the reflection parameter was unserialized. Instead of "Failed to retrieve reflection object" it could say "Cannot call ::isOptional() on an unserialized ReflectionParameter object." Preferable would be to implement a more consistent behavior, so one of the following options: 1. Fully support serialization for reflection objects. Unserializing might possibly trigger autoload, so the class or function can be parsed again (*). Objects referenced from the reflection objects would be serialized too. 2. Support serialization for reflection objects that do not depend on instances. E.g. for classes, static methods and functions, but not for ReflectionObject and things depending on it. 3. Refuse to serialize any reflection objects, including ReflectionParameter. (*) We need to consider the case where code changes between serialization and unserialization.. But this is a known problem with serialization, and not specific to reflection objects. Test script: --------------- <?php class C { static function foo($x = null) {} } $reflMethod = new ReflectionMethod('C', 'foo'); $reflParam = $reflMethod->getParameters()[0]; // Warning: Attempted to serialize unserializable builtin class ReflectionMethod $serReflMethod = serialize($reflMethod); // No warning. $serReflParam = serialize($reflParam); $unserReflParam = unserialize($serReflParam); // Fatal error: ReflectionParameter::isOptional(): Internal error: Failed to retrieve the reflection object $unserReflParam->isOptional(); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70719&edit=1

« previous php.bugs (#196624) next »