|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-08-24 09:26 UTC] mattia dot citterio at gmail dot com
Description:
------------
Cannot serialize/deserialize objects. This is the produced error on the last line:
PHP Fatal error: ReflectionClass::newInstanceArgs(): Internal error: Failed to
retrieve the reflection object
Test script:
---------------
class A {
public function __construct() {
}
}
$r = new ReflectionClass('A');
$r = unserialize(serialize($r));
$a = $r->newInstanceArgs(array());
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 02:00:01 2025 UTC |
This would be very useful, however I can see why this may be problematic for internals. If the class definition has changed since the reflection object was serialized and unserialzed, then it would cause all sorts of issues. The only sensible thing that __wakeup could do is call __construct, and in actual fact, this works: class A { public function __construct() { } } $r = new ReflectionClass('A'); $s = serialize($r); $r1 = unserialize($s); $r1->__construct('A'); $a = $r1->newInstanceArgs(); var_dump($a); So having __wakeup call __construct with the class name would allow reflection to be serialized, if like me, you were hoping to cache reflection using memcached for performance reasons, serialization in this manner would not be beneficial as it would be just as slow to unserialize as to construct a new object.