Bug #70719 [NEW]: ReflectionParameter + serialize()
| From: | andreas at dqxtech dot net | Date: | Thu, 15 Oct 2015 12:22:00 +0000 |
| Subject: | Bug #70719 [NEW]: ReflectionParameter + serialize() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196623@lists.php.net to get a copy of this message | ||
From: andreas at dqxtech dot net
Operating system: Linux
PHP version: 7.0.0RC5
Package: Reflection related
Bug Type: Bug
Bug description:ReflectionParameter + serialize()
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 bug report at https://bugs.php.net/bug.php?id=70719&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70719&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70719&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70719&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70719&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70719&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70719&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70719&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70719&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70719&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70719&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70719&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70719&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70719&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70719&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70719&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70719&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70719&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70719&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70719&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70719&r=mysqlcfg