ArrayAccess/ArrayObject return by reference
| From: | Mike Willbanks | Date: | Wed, 06 Feb 2013 15:27:14 +0000 |
| Subject: | ArrayAccess/ArrayObject return by reference | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-65695@lists.php.net to get a copy of this message | ||
Looking at: http://lxr.php.net/xref/PHP_5_5/Zend/zend_interfaces.c#538
it
seems that ArrayAccess at the moment can not be returned by a reference.
I'm wondering if there was a technical reason behind this or if it is now
a BC reason?
Anyhow; I was attempting to dig through the source code a bit more last
night to see why ArrayObject could not overload the function declaration of
offsetGet to force a return by reference aka: function &offsetGet($key)...
which works now for ArrayAccess but not for ArrayObject. I believe it has
to deal with ArrayObject inheriting ArrayAccess? Is there a way to allow
ArrayObject to change the function declaration in this way? My PHP
internals skills are not the best which is the reason for the question.
Anyhow; justification wise: in userland this leads to a lot of wtf factor.
It really comes down to having to provide our own implementation of
ArrayObject by extending several different areas including ArrayAccess so
that references can be returned so multi-dimensional arrays can be properly
unset aka:
$ar = new ArrayObject(array('foo' => array('bar' => array('baz'
=>
'foo'))));
unset($ar['foo']['bar']['baz']);
Regards,
Mike