i added a (hopefully helpfull) addition to the
online notes regarding magic-functions:
http://www.php.net/manual/en/language.oop.magic-functions.php

Here's what i posted, if anyone's interested:

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 
?>


> -----Original Message-----
> From: Richard Lynch [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 3:52 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Re: issues with __sleep() and __wakeup()
> 
> 
> > class Scott {
> >   var $svar = array(); // free-form hash for whatever data
> >   function Scott( )
> >   {
> > return $this;
> 
> Like, I don't think you're supposed to return $this from your constructor...
> 
> >   }
> >   function __sleep()
> >   {
> 
> According to the manual, this is supposed to return an array of the variable
> names you want serialized.
> 
> return(array('svar'));
> 
> in this case, I think, would be what you want...
> 
> >   }
> >   function __wakeup()
> >   {
> > $this->svar['sleep'] = "I am waking up";
> >   }
> > }// end class
> 
> Once you get it working, post your sample to the User Contributed notes
> please :-)
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to