Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/09/2007, 09:30
zsamer
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
Re: Indexación con Objetos

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

Última edición por zsamer; 25/09/2007 a las 12:01