#29897 [Opn->Bgs]: $array[] syntax does not work with ArrayAccess implementation.

From: Date: Mon, 30 Aug 2004 18:38:06 +0000
Subject: #29897 [Opn->Bgs]: $array[] syntax does not work with ArrayAccess implementation.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-65471@lists.php.net to get a copy of this message
ID: 29897 Updated by: helly@php.net Reported By: sb at sebastian-bergmann dot de -Status: Open +Status: Bogus Bug Type: Scripting Engine problem -Operating System: Not applicable +Operating System: * -PHP Version: 5CVS-2004-08-30 (dev) +PHP Version: 5.* New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Your code is wrong, look @ array_access_007.phpt Previous Comments: ------------------------------------------------------------------------ [2004-08-30 16:10:35] sb at sebastian-bergmann dot de 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29897&edit=1

« previous php.bugs (#65471) next »