php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13912 Array index references inside double quotes cause parse errors
Submitted: 2001-11-02 17:38 UTC Modified: 2001-11-02 17:53 UTC
From: dshearin at e-clecticity dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.6 OS: Redhat Linux - Kernel 2.4.12
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: dshearin at e-clecticity dot net
New email:
PHP Version: OS:

 

 [2001-11-02 17:38 UTC] dshearin at e-clecticity dot net
A parse error results when an increment or decrement operator is used in an array index that falls between double quotes. 

For example:
<?
$a = array(1 => "un", "deux", "trois", "quatre", "cinq");
$i = 1;
while ($i < 5) echo "Number $i is $a[$i++]<br />";
?>

Yields -> Parse error: parse error, expecting `']'' in public_html/testarray.php on line 4

While this works fine: 

while ($i < 5) echo "Number $i is ". $a[$i++] ."<br />";

I think this is part of a larger issue of resolving references inside quoted array indexes. It seems an error occurs whenever using an index that's anything more complicated than a literal value or a simple variable. 

For example, given a function returnNumber() that simply returns whatever number you pass to it, this line produces a parse error:

echo "Number 2 is $a[returnNumber(2)]<br />";

While this one prints out the translation for the number 2, as expected:

echo "Number 2 is ".$a[returnNumber(2)]."<br />";

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 10:01:29 2024 UTC