|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-30 20:38 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
Description: ------------ $array[] syntax does not work with ArrayAccess implementation. Reproduce code: --------------- <?php class TestArray implements ArrayAccess { private $array = array(); public function offsetExists($offset) { return isset($this->array[$offset]); } public function offsetGet($offset) { return $this->array[$offset]; } public function offsetSet($offset, $value) { $this->array[$offset] = $value; } public function offsetUnset($offset) { unset($this->array[$offset]); } } $test = new TestArray; // Does not work. $test[] = 'Hello'; $test[] = ' World!'; // Works. // $test[0] = 'Hello'; $test[1] = ' World!'; print $test[0] . $test[1]; ?> Expected result: ---------------- Hello World! Actual result: -------------- Notice: Undefined offset: 0 in D:\test2.php on line 10 Notice: Undefined offset: 1 in D:\test2.php on line 10