#29897 [NEW]: $array[] syntax does not work with ArrayAccess implementation.
| From: | sb at sebastian-bergmann dot de | Date: | Mon, 30 Aug 2004 14:10:36 +0000 |
| Subject: | #29897 [NEW]: $array[] syntax does not work with ArrayAccess implementation. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-65459@lists.php.net to get a copy of this message | ||
From: sb at sebastian-bergmann dot de
Operating system: Not applicable
PHP version: 5CVS-2004-08-30 (dev)
PHP Bug Type: Scripting Engine problem
Bug description: $array[] syntax does not work with ArrayAccess implementation.
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 bug report at http://bugs.php.net/?id=29897&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29897&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29897&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29897&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=29897&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29897&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29897&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29897&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29897&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29897&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29897&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29897&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29897&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29897&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29897&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29897&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29897&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29897&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29897&r=float