php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72918 Support negative offset inside a quoted string
Submitted: 2016-08-22 09:46 UTC Modified: 2016-10-14 12:47 UTC
From: dams@php.net Assigned: cmb (profile)
Status: Closed Package: *General Issues
PHP Version: 7.1.0beta3 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dams@php.net
New email:
PHP Version: OS:

 

 [2016-08-22 09:46 UTC] 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


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-22 17:58 UTC] git+php at edvin dot io
echo "{$a[-3]}\n"; // Note { and }

Generates the expected output:
------------------------------
c
 [2016-09-27 18:15 UTC] cmb@php.net
-Summary: String negative offset inside a quoted string leads to parse error +Summary: negative offset inside a quoted string leads to parse error
 [2016-10-14 12:47 UTC] cmb@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 -Assigned To: +Assigned To: cmb
 [2016-10-14 12:47 UTC] cmb@php.net
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>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 23:01:30 2024 UTC