|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71614 echo "${str{1}}"; raises syntax error
Submitted: 2016-02-17 04:34 UTC Modified: 2017-01-28 17:42 UTC
From: Assigned:
Status: Re-Opened Package: Strings related
PHP Version: Irrelevant OS: irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2016-02-17 04:34 UTC]
Both ${var} and {$var} are supposed to work, but ${$var} raises syntax error.

Test script:
php > $str = 'abc';

php > echo "${str{1}}";
PHP Parse error:  syntax error, unexpected '{' in php shell code on line 1

php > echo "{$str{1}}";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-17 09:57 UTC]
This "bug" is best solved by deprecating the ${} interpolation syntax for non-expressions.
 [2016-02-18 03:54 UTC]

Deprecating ${} is possible resolution. One concern is ${} is common in shell scripting languages.
 [2016-02-18 23:07 UTC]
-Status: Open +Status: Feedback
 [2016-02-18 23:07 UTC]
Not sure I understand - where's the bug in here and what would you expect to happen? str{1} is not a valid token for variable name, and is not a valid string offset operation since str is not variable - $str is.
 [2016-02-19 05:52 UTC]
-Package: Scripting Engine problem +Package: Documentation problem
 [2016-02-19 05:53 UTC]
Thanks. I didn't think of $$.
We may improve the doc

{$} for variable expression, ${} for variable name resolution and few more examples invalid expressions.
 [2016-02-28 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2016-02-28 21:46 UTC]
-Status: No Feedback +Status: Re-Opened
 [2016-02-28 21:46 UTC]
Document should be more precise about variable and name resolution. Reopened.
 [2017-01-28 17:42 UTC]
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: Strings related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 01:01:28 2024 UTC