#45820 [Opn->Asn]: ArrayObject does not allow empty strings as keys

From: Date: Thu, 30 Oct 2008 10:45:46 +0000
Subject: #45820 [Opn->Asn]: ArrayObject does not allow empty strings as keys
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-130309@lists.php.net to get a copy of this message
ID: 45820 Updated by: felipe@php.net Reported By: toby@php.net -Status: Open +Status: Assigned Bug Type: SPL related Operating System: Gentoo PHP Version: 5.2.6 -Assigned To: +Assigned To: colder Previous Comments: ------------------------------------------------------------------------ [2008-08-14 12:45:46] lstrojny@php.net 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" } } ------------------------------------------------------------------------ [2008-08-14 12:13:57] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45820&edit=1

« previous php.bugs (#130309) next »