Req #62919 [Opn->Sus]: Serialize Reflection

From: Date: Fri, 12 Feb 2021 09:40:45 +0000
Subject: Req #62919 [Opn->Sus]: Serialize Reflection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232079@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62919&edit=1

 ID:                 62919
 Updated by:         cmb@php.net
 Reported by:        mattia dot citterio at gmail dot com
 Summary:            Serialize Reflection
-Status:             Open
+Status:             Suspended
 Type:               Feature/Change Request
 Package:            Reflection related
 Operating System:   Linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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>


Previous Comments:
------------------------------------------------------------------------
[2014-07-10 15:06:30] 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.

------------------------------------------------------------------------
[2012-08-24 09:32:03] laruence@php.net

Reflection* doesn't define their __sleep/__wakeup methods.  so change to FR 
instead of a bug

------------------------------------------------------------------------
[2012-08-24 09:26:19] 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());




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=62919&edit=1


Thread (4 messages)

« previous php.bugs (#232079) next »