php.net |  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: yohgaki@php.net Assigned:
Status: Re-Opened Package: Strings related
PHP Version: Irrelevant OS: irrelevant
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: yohgaki@php.net
New email:
PHP Version: OS:

 

 [2016-02-17 04:34 UTC] yohgaki@php.net
Description:
------------
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}}";
b


Patches

Pull Requests

History

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

Deprecating ${} is possible resolution. One concern is ${} is common in shell scripting languages.

https://www.gnu.org/software/bash/manual/bashref.html
 [2016-02-18 23:07 UTC] stas@php.net
-Status: Open +Status: Feedback
 [2016-02-18 23:07 UTC] stas@php.net
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] yohgaki@php.net
-Package: Scripting Engine problem +Package: Documentation problem
 [2016-02-19 05:53 UTC] yohgaki@php.net
Thanks. I didn't think of $$.
We may improve the doc 
http://jp2.php.net/manual/en/language.types.string.php

{$} 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] yohgaki@php.net
-Status: No Feedback +Status: Re-Opened
 [2016-02-28 21:46 UTC] yohgaki@php.net
Document should be more precise about variable and name resolution. Reopened.
 [2017-01-28 17:42 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: Strings related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 22:01:27 2024 UTC