|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
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..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?