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
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,
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
--
Etienne Kneuss
http://www.colder.ch
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
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,
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
How would the interface enforce returning a reference?
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
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,
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
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);
}
How would the interface enforce returning a reference?
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
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
On Wed, 06 Feb 2013 17:47:15 +0100, Anthony Ferrara ircmaxell@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...
How would this solve anything? The BC problem is that ArrayObject doesn't
return by reference. If we made it return by reference, almost all* the
now valid subclasses that also do not return by reference would issue an
E_STRICT.
*"almost" because you can override ArrayObject's offsetGet and return by
reference. Those would be compatible with the modification in ArrayObject.
We've allowed overrides to return by reference when the parent doesn't for
quite a while now.
--
Gustavo Lopes