I just wanted to check to make sure I have this right. I have a class with some members as just string values but then also an array of references to other objects (of itself). When the object is serialized, will it also serialize all of those references? Ex:
class Test {
protected static $_not_needed;
protected $_title;
protected $_tests = array();
public function __construct($title) {
$this->_title = (string) $title;
}
public function __sleep() {
return array("\0*\0_title", "\0*\0_tests");
}
public function addTest(self $test) {
$this->_tests[] = $test;
}
}
$test = new Test('abc');
$test->addTest(new Test('123'));
$test->addTest(new Test('456'));
$test->addTest(new Test('789'));
$serialized = serialize($test);
$unserialized = unserialize($serialized);
Or do I have to serialized the references first?
public function __sleep() {
foreach ($this->_tests as &$test) {
$test = serialize($test);
}
return array("\0*\0_title", "\0*\0_tests");
}
public function __wakeup() {
foreach ($this->_tests as &$test) {
$test = unserialize($test);
}
}