note 14473 added to language.oop.magic-functions.php

From: Date: Wed, 01 Aug 2001 15:33:16 +0000
Subject: note 14473 added to language.oop.magic-functions.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-16167@lists.php.net to get a copy of this message
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 ?> http://www.php.net/manual/en/language.oop.magic-functions.php

« previous php.notes (#16167) next »