php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45820 ArrayObject does not allow empty strings as keys
Submitted: 2008-08-14 12:13 UTC Modified: 2008-12-30 23:34 UTC
From: toby@php.net Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.2.6 OS: Gentoo
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: toby@php.net
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-14 12:45 UTC] 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-12-30 23:34 UTC] colder@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC