Bug #71611 [Com]: array index starting with number in double quote string
| From: | carusogabriel@php.net | Date: | Sun, 09 Sep 2018 01:14:29 +0000 |
| Subject: | Bug #71611 [Com]: array index starting with number in double quote string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216939@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71611&edit=1
ID: 71611
Comment by: carusogabriel@php.net
Reported by: asylow at free dot fr
Summary: array index starting with number in double quote
string
Status: Open
Type: Bug
Package: *General Issues
PHP Version: 5.6.18
Block user comment: N
Private report: N
New Comment:
The change for this bug may also affect the way we declare variables starting with a number: https://3v4l.org/dVGQD
Previous Comments:
------------------------------------------------------------------------
[2016-02-16 23:23:53] 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
------------------------------------------------------------------------
[2016-02-16 18:27:26] 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 ']'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71611&edit=1