note 103936 added to class.serializable
| From: | Anonymous at osu1 dot php dot net | Date: | Thu, 12 May 2011 13:09:23 +0000 |
| Subject: | note 103936 added to class.serializable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179656@lists.php.net to get a copy of this message | ||
You can prevent an object getting unserialized by returning NULL. Instead of a serialized object,
PHP will return the serialized form of NULL:
<?php
class testNull implements Serializable {
public function serialize() {
return NULL;
}
public function unserialize($data) {
}
}
$obj = new testNull;
$string = serialize($obj);
echo $string; // "N;"
?>
That's perhaps better than throwing exceptions inside of the serialize function if you want to
prevent serialization of certain objects.
----
Server IP: 69.147.83.197
Probable Submitter: 79.225.61.4
----
Manual Page -- http://www.php.net/manual/en/class.serializable.php
Edit -- https://master.php.net/note/edit/103936
Del: integrated -- https://master.php.net/note/delete/103936/integrated
Del: useless -- https://master.php.net/note/delete/103936/useless
Del: bad code -- https://master.php.net/note/delete/103936/bad+code
Del: spam -- https://master.php.net/note/delete/103936/spam
Del: non-english -- https://master.php.net/note/delete/103936/non-english
Del: in docs -- https://master.php.net/note/delete/103936/in+docs
Del: other reasons-- https://master.php.net/note/delete/103936
Reject -- https://master.php.net/note/reject/103936
Search -- https://master.php.net/manage/user-notes.php