note 102958 deleted from function.session-write-close by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Mar 2011 21:32:13 +0000 |
| Subject: | note 102958 deleted from function.session-write-close by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177944@lists.php.net to get a copy of this message | ||
Note Submitter: McGlockenshire at my name dot com
----
@joadha at gmail dot com: That is completely and entirely incorrect. Serialized objects do retain
their private and protected members.
<?php
class Foo {
private $bar;
public $baz;
public function setBar($data) { $this->bar = $data; }
public function getBar() { return $this->bar; }
}
$f = new Foo();
$f->setBar("I am Bar");
$f->baz = "I am Baz";
$s = serialize($f);
echo $s;
$not_f = unserialize($s);
echo $not_f->getBar(); // "I am Bar"
?>
Now, it happens that private and protected members get null bytes prepended to their names, but that
should not impact anything whatsoever as long as you store them in a way that won't get
disrupted by the null byte. You can even safely strip the null byte from the name and still get the
data restored properly.