Hola También puedes usar Colecciones de objetos que vienen en el motor de PHP5 tales como
SplObjectStorage
y
ArrayObject
las cuales implementan interfaces tales como ArrayAccess,I teratorAggregate, countable etc...
Más Info sobre
SPL (Standard PHP Library),
http://www.php.net/~helly/php/ext/spl/ y un excelente
Artículo de Zend Devzone
Aquí tienes un ejemplo de SplObjectStorage:
Código PHP:
<?php
/**
* Test class that we will store in the
* SplObjectStorage object.
*/
class StorageTest {
private $title;
public function __construct( $title ) {
$this->title = $title;
}
public function __toString() {
return $this->title;
}
}
$storage = new SplObjectStorage();
$obj1 = new StorageTest( "wiki.cc" );
$obj2 = new StorageTest( "wiki2.cc" );
$storage->attach( $obj1 );
$storage->attach( $obj2 );
foreach( $storage as $obj ) {
echo $obj . "\n";
}
if( $storage->contains( $obj1 ) ) {
echo "storage contains the object\n";
} else {
echo "storage does NOT contain the object\n";
}
$storage->detach( $obj1 );
if( $storage->contains( $obj1 ) ) {
echo "storage contains the object\n";
} else {
echo "storage does NOT contain the object\n";
}
?>
salu2