note 80173 deleted from language.oop.serialization by danbrown

From: Date: Sat, 07 Nov 2009 19:12:46 +0000
Subject: note 80173 deleted from language.oop.serialization by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162596@lists.php.net to get a copy of this message
Note Submitter: balduran at hot dot ee ---- This is an interesting thing with classes when B extends A, then private variable of class A will not be serialized when using magic method __sleep(). Without __sleep() it works fine. class A { public $a1 = 'a1'; protected $a2 = 'a2'; private $a3 = 'a3'; public function __sleep() { // option 1: wont work, says: // Notice: serialize() [function.serialize]: "a3" returned as member variable from __sleep() but does not exist in **/index.php on line ** return $this; // option 2: wont work, says: // Notice: serialize() [function.serialize]: "a3" returned as member variable from __sleep() but does not exist in **/index.php on line ** $keys = array(); foreach( $this as $key => $value) $keys[] = $key; return $vals; } } class B extends A { public $b1 = 'b1'; public $b2 = 'b2'; public $b3 = 'b3'; } print_r(unserialize(serialize(new B()))); Not sure if this is bug or feature.

« previous php.notes (#162596) next »