php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55324 No documentation for accessing array elements with curly braces
Submitted: 2011-07-30 12:29 UTC Modified: 2012-11-14 17:08 UTC
From: kieran at menor dot dk Assigned: googleguy (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.6 OS: Windows 7
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kieran at menor dot dk
New email:
PHP Version: OS:

 

 [2011-07-30 12:29 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-30 12:31 UTC] kieran at menor dot dk
Made a tiny mistake. Obviously, the expected result for line 9 in the script is "a" and not "123".
 [2011-07-30 12:32 UTC] kieran at menor dot dk
And obviously, I meant to correct line 10, not line 9. >_>
 [2012-11-14 17:07 UTC] googleguy@php.net
Automatic comment from SVN on behalf of googleguy
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=328358
Log: Added note for accessing array elements with curly braces - fixes bug #55324
 [2012-11-14 17:08 UTC] googleguy@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2012-11-14 17:08 UTC] googleguy@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: googleguy
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 13:00:02 2026 UTC