- serialize: documentation ( source)
<?php
class Test implements ArrayAccess {
private $data = array();
/** Array Access */
public function offsetExists($offset)
{
return isset($this->data[$offset]);
}
public function &offsetGet($offset)
{
return $this->data[$offset];
}
public function offsetSet($offset, $value)
{
$this->data[$offset] = $value;
}
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
}
class Test2 extends ArrayObject {
public function &offsetGet($offset)
{
$t =& parent::offsetGet($offset);
return $t;
}
}
$t = new Test();
$t['test'] = array(1,2,3,4);
echo serialize($t)."\n";
$t['test'][] = 5;
echo serialize($t)."\n";
$t = new Test2();
$t['test'] = array(1,2,3,4);
echo serialize($t)."\n";
$t['test'][] = 5;
echo serialize($t)."\n";