In PHP 5.4 I have an instance of SplObjectStorage where I associate objects with some extra metadata. I need to then iterate through the instance of SplObjectStorage and retrieve the object associated with the current key. I attempted to use SplObjectStorage::key but that did not work (but may work in PHP 5.5).
Here is a simplified version of what I am attempting to do:
$storage = new SplObjectStorage;
$foo = (object)['foo' => 'bar'];
$storage->attach($foo, ['room' => 'bar'];
foreach ($storage as $value) {
print_r($value->key());
}
All I really need is some way to retrieve the actual object that is associated with the key. It is not even possible to manually create a separate indexed array with the numeric index and the object SplObjectStorage points to, as far as I can tell.