note 14473 deleted from language.oop.magic-functions by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Nov 2009 18:55:18 +0000 |
| Subject: | note 14473 deleted from language.oop.magic-functions by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162516@lists.php.net to get a copy of this message | ||
Note Submitter: scott at graphictype dot com
----
Here is a sample class and some test statements to demonstrate how __sleep() is used.
If you do not return anything from __sleep(), your object will *not* be serialized. You must return
something from __sleep() to tell serialize what to serialize.
<?
// to test the class
$x = new Scott();
print_r($x);
$y = serialize($x);
$z = unserialize($y);
print_r($z);
// Simple class to test __sleep()
class Scott {
// class variables
var $error;
var $svar = array();
// constructor
function Scott() {
$this->svar['Hello'] = "World";
}
function __sleep() {
$this->svar['Hello'] = "Yawn";
// return list of instance-variables to be serialized
return array('error', 'svar');
}
function __wakeup() {
$this->svar['test'] = "I'm here!";
}
}// end class
?>