php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15677 quoted array index in string should be possible
Submitted: 2002-02-22 09:42 UTC Modified: 2011-01-01 00:45 UTC
Votes:8
Avg. Score:4.5 ± 0.9
Reproduced:6 of 7 (85.7%)
Same Version:2 (33.3%)
Same OS:2 (33.3%)
From: hartmut at six dot de Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.1.1 OS: *
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: hartmut at six dot de
New email:
PHP Version: OS:

 

 [2002-02-22 09:42 UTC] hartmut at six dot de
<?php echo "$array[index]"; ?>

works while

<?php echo "$array['index']"; ?>

gives

PHP Parse error:  parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in - on line 1

the error message is not very helpfull (knowing the exact character position in the line would help a little bit, but that's another story) and the different syntax requirements for array indices within and outside of strings are somtimes confusing for newbies, too

so "$array['index']" should be supported by the parser

PS: i know about "{$array['index']}", but that is not the point ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-08 14:05 UTC] destes at ix dot netcom dot com
I would very much like to see this implemented soon.  Since PHP has said (at least in the manual) that it is trying to get away from $array[index] syntax and into $array['index'] syntax, support for this syntax directly in strings would help very much.

-Steve
 [2011-01-01 00:45 UTC] jani@php.net
Over 7 years and we still have survived with {} around these. Plus they make stuff more readable.
 [2011-01-01 00:45 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: Scripting Engine problem
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 17:01:28 2025 UTC