How to get the object associated with the current key while iterating through SplObjectStorage in PHP 5.4
Do it:
$storage = new SplObjectStorage;
$foo = (object)['foo' => 'bar'];
$storage->attach($foo, ['room' => 'bar']);
foreach ($storage as $value) {
$obj = $storage->current(); // current object
$assoc_key = $storage->getInfo(); // return, if exists, associated with cur. obj. data; else NULL
var_dump($obj);
var_dump($assoc_key);
}
See more SplObjectStorage::current and SplObjectStorage::getInfo.