In the following code:
$storage = new \SplObjectStorage(); $fooA = new \StdClass(); $fooB = new \StdClass(); $storage[$fooA] = 1; $storage[$fooB] = array(); $storage[$fooA] = 2; $storage[$fooB][] = 'test';
I would expect $storage[$fooA]
1
, which is. I would also expect $storage[$fooB]
be array('test')
, which is not the case. It also triggers a notification that states: "Indirect modification of an overloaded SplObjectStorage element does not affect ..."
I think this is because the implementation of ArrayAccess
in SplObjectStorage
does not return a value by reference.
Is it possible to use SplObjectStorage
as a data map, where keys are objects and values ββare mutable arrays? Are there other viable options for doing this kind of work?
source share