|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-05-28 10:20 UTC] tomas_matousek at hotmail dot com
[2005-05-28 11:46 UTC] tony2001@php.net
[2005-05-28 14:31 UTC] tomas_matousek at hotmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 23 22:00:02 2025 UTC |
Description: ------------ I looks like you have never do in-depth testing with ArrayAccess. I you did you must realize many things are wrong there. It took me less then 5 minutes to kill PHP several times using this naively implemented feature. Reproduce code: --------------- class ArrayClass implements ArrayAccess { public $a = array(); function offsetExists($index) { return array_key_exists($index, $this->a); } function offsetGet($index) { return $this->a[$index]; } function offsetSet($index, $newval) { return $this->a[$index] = $newval; } function offsetUnset($index) { unset($this->a[$index]); } } Expected result: ---------------- It's unclear for me what should I expect. Definitly not the crashes. Can anyone explain, what should I expect from e.g. $obj[1][2][3] = 1; ? And what should $a =& $obj[1][2][3]; do? Actual result: -------------- $obj[array()] = 1; // crash $obj[][] = 1; // crash $x =& $obj[1] // crash $obj[$obj[1]] = 1; // if offsetGet() returns null, the offsetSet() is called then $obj[1]++; // doesn't work at all even if both offsetGet and offsetSet are modified to return by reference