Tyler,

References are indicated by the function signature, so:

interface ArrayAccessReference {
    public function &offsetGet($key);
    public function offsetSet($key, $value);
    public function offsetIsset($key);
    public function offsetUnset($key);
}


On Wed, Feb 6, 2013 at 12:09 PM, Tyler Sommer <somme...@gmail.com> wrote:

> How would the interface enforce returning a reference?
>
>
> On Feb 6, 2013, at 8:47 AM, Anthony Ferrara <ircmax...@gmail.com> wrote:
>
> > 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 <col...@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 <pen...@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
> >>
>
>

Reply via email to