Bug #72918 [Com]: String negative offset inside a quoted string leads to parse error
Edit report at https://bugs.php.net/bug.php?id=72918&edit=1
ID: 72918
Comment by: git+php at edvin dot io
Reported by: dams@php.net
Summary: String negative offset inside a quoted string leads
to parse error
Status: Open
Type: Bug
Package: *General Issues
Operating System: Any
PHP Version: 7.1.0beta3
Block user comment: N
Private report: N
New Comment:
echo "{$a[-3]}\n"; // Note { and }
Generates the expected output:
------------------------------
c
Previous Comments:
------------------------------------------------------------------------
[2016-08-22 09:46:07] dams@php.net
Description:
------------
Negative offset in strings works well, except when the variable is inside another string.
The error works on strings, but also on arrays with negative index in arrays.
The problem also appears in previous versions of PHP, both for array and string.
Test script:
---------------
<?php
$a = "abcde";
//$a = array( -3 => 2);
//It works on arrays too.
echo $a[-3]."\n";
echo "$a[-3]\n";
?>
Expected result:
----------------
c
c
Actual result:
--------------
Parse error: syntax error, unexpected '-', expecting identifier (T_STRING) or variable
(T_VARIABLE) or number (T_NUM_STRING) in test.php on line 6
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72918&edit=1
Thread (3 messages)