Doc #55324 [Opn]: No documentation for accessing array elements with curly braces
| From: | kieran at menor dot dk | Date: | Sat, 30 Jul 2011 12:31:37 +0000 |
| Subject: | Doc #55324 [Opn]: No documentation for accessing array elements with curly braces | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-6955@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55324&edit=1
ID: 55324
User updated by: kieran at menor dot dk
Reported by: kieran at menor dot dk
Summary: No documentation for accessing array elements with
curly braces
Status: Open
Type: Documentation Problem
Package: Documentation problem
Operating System: Windows 7
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Made a tiny mistake. Obviously, the expected result for line 9 in the script is "a" and
not "123".
Previous Comments:
------------------------------------------------------------------------
[2011-07-30 12:29:38] kieran at menor dot dk
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55324&edit=1