note 80173 added to language.oop.serialization
| From: | balduran at hot dot ee | Date: | Wed, 02 Jan 2008 21:36:58 +0000 |
| Subject: | note 80173 added to language.oop.serialization | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134666@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 194.145.210.3
Probable Submitter: 88.196.45.130
----
Manual Page -- http://www.php.net/manual/en/language.oop.serialization.php
Edit -- https://master.php.net/note/edit/80173
Del: integrated -- https://master.php.net/note/delete/80173/integrated
Del: useless -- https://master.php.net/note/delete/80173/useless
Del: bad code -- https://master.php.net/note/delete/80173/bad+code
Del: spam -- https://master.php.net/note/delete/80173/spam
Del: non-english -- https://master.php.net/note/delete/80173/non-english
Del: in docs -- https://master.php.net/note/delete/80173/in+docs
Del: other reasons-- https://master.php.net/note/delete/80173
Reject -- https://master.php.net/note/reject/80173
Search -- https://master.php.net/manage/user-notes.php