|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-14 12:13 UTC] toby@php.net
Description:
------------
While '' works as an array key, it does not work with ArrayObject. It should either work both or none (first one preferred).
Reproduce code:
---------------
php > $foo = new ArrayObject();
php > $foo[''] = 'lala';
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An offset must not begin with \0 or be empty' in php shell code:1
Stack trace:
#0 php shell code(1): unknown()
#1 {main}
thrown in php shell code on line 1
InvalidArgumentException: An offset must not begin with \0 or be empty in php shell code on line 1
Call Stack:
16.7554 63916 1. {main}() php shell code:0
Expected result:
----------------
Same as for arrays.
php > $foo = array();
php > $foo[''] = 'lala';
php > var_dump($foo);
array(1) {
[""]=>
string(4) "lala"
}
Actual result:
--------------
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An offset must not begin with \0 or be empty' in php shell code:1
Stack trace:
#0 php shell code(1): unknown()
#1 {main}
thrown in php shell code on line 1
InvalidArgumentException: An offset must not begin with \0 or be empty in php shell code on line 1
Call Stack:
16.7554 63916 1. {main}() php shell code:0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 06:00:01 2025 UTC |
In 5.3 it behaves differently: $ php -r '$a = new ArrayObject(); $a[''] = "foo"; var_dump($a);' object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(1) { [0]=> string(3) "foo" } }