|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-07-30 12:31 UTC] kieran at menor dot dk
[2011-07-30 12:32 UTC] kieran at menor dot dk
[2012-11-14 17:07 UTC] googleguy@php.net
[2012-11-14 17:08 UTC] googleguy@php.net
[2012-11-14 17:08 UTC] googleguy@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: googleguy
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 08 15:00:02 2026 UTC |
Description: ------------ I have only seen documentation for using $var{n} syntax for accessing single characters in strings. Apparently, it is completely interchangeable with $var[n] for arrays as well. Is this intended? Seeing as it is only noted that strings may be accessed using curly braces, I would expect the variable to be typecast to string. Test script: --------------- <?php $foo = array('123'); $bar = 'abc'; echo $foo . "\r\n"; // Outputs "Array", as expected echo $bar . "\r\n"; // Outputs "abc", as expected echo $foo[0] . "\r\n"; // Outputs "123", as expected echo $bar[0] . "\r\n"; // Outputs "123", as expected echo $foo{0} . "\r\n"; // Outputs "123", undocumented (?), expected implicit cast to string, thus expected the output to be "A" echo $bar{0} . "\r\n"; // Outputs "a", as expected ?> Expected result: ---------------- Array abc 123 a A a Actual result: -------------- Array abc 123 a 123 a