Bug->Req #72918 [Opn->Csd]: Support negative offset inside a quoted string
Edit report at https://bugs.php.net/bug.php?id=72918&edit=1
ID: 72918
Updated by: cmb@php.net
Reported by: dams@php.net
-Summary: negative offset inside a quoted string leads to
parse error
+Summary: Support negative offset inside a quoted string
-Status: Open
+Status: Closed
-Type: Bug
+Type: Feature/Change Request
Package: *General Issues
Operating System: Any
PHP Version: 7.1.0beta3
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
We don't consider this behavior as bug, but rather that supporting
negative numeric indices is an enhancement. This will be available
as of PHP 7.1.0.
Cf. <http://git.php.net/?p=php-src.git;a=commit;h=2cc3aeb4b98bcbc9572041b2f7d3276aabd51aae>
and <http://svn.php.net/viewvc?view=revision&revision=340479>.
Previous Comments:
------------------------------------------------------------------------
[2016-08-22 17:58:58] git+php at edvin dot io
echo "{$a[-3]}\n"; // Note { and }
Generates the expected output:
------------------------------
c
------------------------------------------------------------------------
[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)