- var_dump: documentation ( source)
<?php
class IdObjectStorage extends SplObjectStorage {
public function getHash($object) { return (string) $object->id; }
}
$storage = new IdObjectStorage(); $array = [];
$object1 = new stdClass(); $object1->id = 1; $object1->value = 'Object #1';
$storage->attach($object1);
$array[$object1->id] = $object1;
foreach($storage as $x) var_dump($x->value); // Object #1
foreach($array as $x) var_dump($x->value); // Object #1
$object2 = new stdClass(); $object2->id = 1; $object2->value = 'Object #2';
$array[$object2->id] = $object2;
$storage->attach($object2);
foreach($storage as $x) var_dump($x->value); // Object #1
foreach($array as $x) var_dump($x->value); // Object #2