Edit report at https://bugs.php.net/bug.php?id=34783&edit=1

 ID:                 34783
 Comment by:         me at achronos dot ca
 Reported by:        oliver dot graetz at gmx dot de
 Summary:            Contradictory errors using ArrayAccess
 Status:             Not a bug
 Type:               Bug
 Package:            SPL related
 Operating System:   WinXP, Debian Linux
 PHP Version:        5.1.0RC1
 Block user comment: N
 Private report:     N

 New Comment:

Although no php dev has ever mentioned it in a bug report (that I can find), 
this issue has in fact been fixed.
At least, it has been fixed for ArrayAccess.
(For ArrayObject, I haven't tested.)

According to the PHP docs (http://php.net/manual/en/arrayaccess.offsetget.php 
notes section)
this was fixed in 5.3.4 by relaxing the requirements for implementing 
AccessAccess, so that
 public function &offsetGet($offset) {}
works, and thus indirect access works.

I've confirmed this does in fact work (on 5.3.8).

There are multiple bug reports all related to this topic:
 https://bugs.php.net/bug.php?id=51622
 https://bugs.php.net/bug.php?id=34783
 https://bugs.php.net/bug.php?id=32983


Previous Comments:
------------------------------------------------------------------------
[2011-05-26 03:43:01] tohru at reedom dot com

It's a bug since the current behavior breaks the Liskov's Substitution Principle
when a subclass just overrides offsetGet().
http://www.oodesign.com/liskov-s-substitution-principle.html

------------------------------------------------------------------------
[2010-08-03 16:27:49] georgwaechter at googlemail dot com

Hi Oliver,

in my opinion you are absolutely right! I'm struggling with this "bug" for 
months now. The interface ArrayAccess is actually really useless until some 
serious php developers undestand that its essential that ArrayAccess objects 
behave like normal arrays. For modern object oriented programming this is 
simply a must. Enhanced this means that all array related functions work with 
those objects too.

The current implementation is not complete.

Greets

Georg

------------------------------------------------------------------------
[2005-10-07 23:09:33] oliver dot graetz at gmx dot de

Perhaps there shouldn't be afix for the reference issues since they are not 
meant to happen looking at the interface. But 
$data['element']['element2']="hi"; should definitely work! Perhaps a fix to 
look if the first part of this code is accessing an object instead of a real 
array has to be applied. An ordinary user sees nothing of a reference. Either 
fix this with ArrayAccess or completely yank the interface! 

I see a future where more and more framework code is pretending to be an array. 
If then users get this error message they won't understand the world. "It's an 
array!? Where's the reference? Why the *#?* isn't this working? I hate PHP5!"

If you implement code so something can look like an array than it MUST be able 
to truely behave like an array.

------------------------------------------------------------------------
[2005-10-07 22:40:50] oliver dot graetz at gmx dot de

Why did this work in 5.0.3 by using &offsetGet() and can't be made to work in 
5.1? Why would changing the interface to read &offsetGet break anything other 
than the (up to now) few apps DEFINING it without the ampersand? 5.0 didn't 
complain about this at all and it worked. The issues caused by a simple change 
of the interface a far inferior to those caused by the "only variables can be 
passed by reference" some weeks ago. And you're avoiding more serious trouble 
in later versions when more and more applications are relying on the false 
behaviour?

------------------------------------------------------------------------
[2005-10-07 21:41:03] oliver dot graetz at gmx dot de

Won't happen. I'm just a user of PHP. As a result, this is one more case where 
using a new feature becomes impossible by breaking BC (between 5.0 and 5.1). A 
yound and promising feature has to be left behind, ArrayAccess won't be in use 
any more in future projects by certain people since the desired behaviour can 
easily be achieved by using ordinary methods. Syntactic sugar going to hell.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=34783


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=34783&edit=1

Reply via email to