problem with serialize and magic method __sleep()
Posted: Mon Jun 05, 2006 8:58 pm
See code:
The output of this script gives us:
Which is showing us that the object isn't being properly serialized for some reason. If you remove the magic __sleep() function, everything serializes correctly:
this gives us the expected output of:
Code: Select all
<?php
class test{
private $prop = 'blah';
public function __sleep(){
echo 'going to sleep';
}
}
$test = new test();
echo serialize($test);
?>Code: Select all
going to sleepN;Code: Select all
<?php
class test{
private $prop = 'blah';
/*
public function __sleep(){
echo 'going to sleep';
}
*/
}
$test = new test();
echo serialize($test);
?>Code: Select all
O:4:"test":1:{s:10:"