note 104747 added to class.serializable
| From: | Anonymous at osu1 dot php dot net | Date: | Tue, 05 Jul 2011 14:01:02 +0000 |
| Subject: | note 104747 added to class.serializable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181251@lists.php.net to get a copy of this message | ||
You cannot throw an exception inside the serialize() method. This will cause PHP to complain that
you are not returning a string or NULL.
The best way to prevent the serialization of an object is to throw an Exception in the __sleep()
method:
<?php
class Obj {
public function __sleep() {
throw new BadMethodCallException('You cannot serialize this object.');
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 98.103.79.230
----
Manual Page -- http://www.php.net/manual/en/class.serializable.php
Edit -- https://master.php.net/note/edit/104747
Del: integrated -- https://master.php.net/note/delete/104747/integrated
Del: useless -- https://master.php.net/note/delete/104747/useless
Del: bad code -- https://master.php.net/note/delete/104747/bad+code
Del: spam -- https://master.php.net/note/delete/104747/spam
Del: non-english -- https://master.php.net/note/delete/104747/non-english
Del: in docs -- https://master.php.net/note/delete/104747/in+docs
Del: other reasons-- https://master.php.net/note/delete/104747
Reject -- https://master.php.net/note/reject/104747
Search -- https://master.php.net/manage/user-notes.php