Re: ArrayAccess/ArrayObject return by reference

From: Date: Wed, 06 Feb 2013 16:47:15 +0000
Subject: Re: ArrayAccess/ArrayObject return by reference
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-65697@lists.php.net to get a copy of this message
Perhaps there's another way out of this. A simple way would be to introduce an ArrayAccessReference interface in core that adds the references to the getters/setters... It's perhaps not the cleanest, but it solves the BC issues... Anthony On Wed, Feb 6, 2013 at 11:42 AM, Etienne Kneuss <colder@php.net> wrote: > I assume it would be possible technically but might break (at least by > issuing E_STRICT) a lot of code if we forced ArrayObject::offsetGet to > return a reference. > > Think of all the subclasses that extend ArrayObject who currently do not do > that? > > Other than that, returning a ref where it previously didn't can have all > kinds of undesirable and hard-to-track consequences. > > Best, > > > On Wed, Feb 6, 2013 at 4:27 PM, Mike Willbanks <pencap@gmail.com> wrote: > > > Looking at: > > http://lxr.php.net/xref/PHP_5_5/Zend/zend_interfaces.c#538it > > 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 > > > > > > -- > Etienne Kneuss > http://www.colder.ch >

« previous php.internals (#65697) next »