note 88079 added to class.arrayaccess

From: Date: Fri, 09 Jan 2009 01:33:42 +0000
Subject: note 88079 added to class.arrayaccess
Groups: php.notes 
Request: Send a blank email to php-notes+get-148977@lists.php.net to get a copy of this message
Note that at least in PHP 5.1, objects implementing ArrayAccess cannot return objects by reference. See http://bugs.php.net/bug.php?id=34783 . If you have code like <?php $x = &$y[0]; ?> then this will (as far as I can tell) *always* fail unless $y is a real array -- it cannot work if $y is an object implementing ArrayAccess. If your offsetGet() function returns by reference, you get the fatal error "Declaration of MyClass::offsetGet() must be compatible with that of ArrayAccess::offsetGet()". If you try to have it return by value, however, you get the (contradictory) fatal error "Objects used as arrays in post/pre increment/decrement must return values by reference", at least in my version of PHP. It is therefore not possible to take arbitrary code dealing with arrays and try to substitute an object of your own for an array, even if all of the normal array functions didn't fail as well (which they do, or at least some of them). ---- Server IP: 69.147.83.197 Probable Submitter: 72.229.28.14 ---- Manual Page -- http://www.php.net/manual/en/class.arrayaccess.php Edit -- https://master.php.net/note/edit/88079 Del: integrated -- https://master.php.net/note/delete/88079/integrated Del: useless -- https://master.php.net/note/delete/88079/useless Del: bad code -- https://master.php.net/note/delete/88079/bad+code Del: spam -- https://master.php.net/note/delete/88079/spam Del: non-english -- https://master.php.net/note/delete/88079/non-english Del: in docs -- https://master.php.net/note/delete/88079/in+docs Del: other reasons-- https://master.php.net/note/delete/88079 Reject -- https://master.php.net/note/reject/88079 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148977) next »