php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62919 Serialize Reflection
Submitted: 2012-08-24 09:26 UTC Modified: 2021-02-12 09:40 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: mattia dot citterio at gmail dot com Assigned:
Status: Suspended Package: Reflection related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mattia dot citterio at gmail dot com
New email:
PHP Version: OS:

 

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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-24 09:32 UTC] laruence@php.net
-Type: Bug +Type: Feature/Change Request
 [2012-08-24 09:32 UTC] laruence@php.net
Reflection* doesn't define their __sleep/__wakeup methods.  so change to FR 
instead of a bug
 [2014-07-10 15:06 UTC] tom at r dot je
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.
 [2021-02-12 09:40 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2021-02-12 09:40 UTC] cmb@php.net
Indeed, this feature request is somewhat doubtful, and as such
needs to be discussed.  If anyone is still interested in having
this, please pursue the RFC process[1].  For the time being, I'm
suspending this ticket.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 08:01:26 2024 UTC