php.net |  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
Votes:1
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
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

eg.
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] alan_k@php.net
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
s/surising/surprising/g

:)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC