This code is an example. By using classes like this, you gives a chance to create classes which extends another class but have most of the ability what a class extends ArrayObject (like multiple inheritance):
<?php
class foo
{
public $foo = 'foo';
} class foobar extends foo implements ArrayAccess,IteratorAggregate,Countable
{
public function offsetExists($offset)
{
$array = array(1, 2, 3, 4);
return array_key_exists($offset, $array);
}
public function offsetGet($offset)
{
$array = array(1, 2, 3, 4);
return $array[$offset];
}
public function offsetSet($offset, $value)
{
}
public function offsetUnset($offset)
{
}
function count()
{
$array = array(1, 2, 3, 4);
return count($array);
} function getArray()
{
return array(1, 2, 3, 4);
} function getIterator()
{
return new ArrayIterator(array(1, 2, 3, 4));
} function __toString()
{
return 'String test';
} } $foobar = new foobar();
print $foobar[0].'<br/>';
print $foobar->foo.'<br/>';
print count($foobar).'<br/>';
foreach ($foobar as $k=>$v)
{
print $k.'=>'.$v.'<br/>';
} var_dump($foobar->getArray());
print $foobar;
?>
For proper use you must be define all these methods except getArray()
Browse SPL's sources to be a very helpful think.
ps.: sry for my english