note 104747 deleted from class.serializable by googleguy
| From: | googleguy@php.net | Date: | Sun, 18 Oct 2015 22:37:37 +0000 |
| Subject: | note 104747 deleted from class.serializable by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203982@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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.');
}
}
?>