php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71611 array index starting with number in double quote string
Submitted: 2016-02-16 18:27 UTC Modified: 2016-02-16 23:23 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:-2 (-100.0%)
From: asylow at free dot fr Assigned:
Status: Open Package: *General Issues
PHP Version: 5.6.18 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-02-16 18:27 UTC] asylow at free dot fr
Description:
------------
In a double quoted string, an array index beginning with numbers followed by letters  is not correctly interpreted.

The documentation regarding Nowdocs says : "With array indices, the closing square bracket (]) marks the end of the index." but the parser seems to stop at the first alpha character.

Of course this can be treated with the "Complex (curly) syntax" but "1a" is not more complex than "a1".



Test script:
---------------
$array['a1'] = 'foo';
echo "$donnees[a1]";
// foo

$array['1a'] = 'foo';
echo "$donnees[1a]";
// Parse error: syntax error, unexpected 'a' (T_STRING), expecting ']'



Expected result:
----------------
foo
foo

Actual result:
--------------
Parse error: syntax error, unexpected 'a' (T_STRING), expecting ']'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-16 23:23 UTC] yohgaki@php.net
This may be fixed, but working syntax is

echo "${array['1a']}";
or
echo "{$array['1a']}";

You should use {} for complex expression. We need improvement for string offset, though.

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

php > echo "{$str{1}}";
b
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC