|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18103 Incorrect behavior of multi-dimensional Array
Submitted: 2002-07-01 23:26 UTC Modified: 2002-07-02 02:59 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: stephung at mosp dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.1 OS: ALL
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: stephung at mosp dot net
New email:
PHP Version: OS:


 [2002-07-01 23:26 UTC] stephung at mosp dot net
The following code:

$test['foo'] = "abc";
$test['foo']['bar'] = "123";

echo $test['foo'];    // Output "1bc"

The output is "1bc".  IMO, "abc" would be the only semantically correct output, although "Array" is also acceptable, which means value "abc" is replaced by array( 'bar' => "123").  The actual output "1bc" is definietly not correct.  This happens on all versions of PHP.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-01 23:35 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at
 [2002-07-01 23:36 UTC]
it is the correct behaviour 
since test['foo'] is a string, using an array '[]' on a string returns the character:

echo $test['foo'][1]; //will equal 'b'

since ['bar'] evalates to 0 (zero)
it will replace character 'a' with the first character of "123"..

it would be nice to emit warnings on string[] format as string{n} is the advised method of using string position retreival/setting..

 [2002-07-01 23:37 UTC]
two at the same time :)
 [2002-07-02 02:57 UTC] stephung at mosp dot net
Wow, this is a surising side effect when string position retreival operator is the same as array operator.  Is there any way/plan to force [] as array operator and {} as string position opeartor?
 [2002-07-02 02:59 UTC] stephung at mosp dot net

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 05:03:33 2021 UTC