php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #993 GLOBAL ${$x[$i]} gives parse error
Submitted: 1998-12-17 04:51 UTC Modified: 2000-07-18 10:32 UTC
From: vogtner at soldan dot de Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.5 OS: Solaris 2.5.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vogtner at soldan dot de
New email:
PHP Version: OS:

 

 [1998-12-17 04:51 UTC] vogtner at soldan dot de
<%    
      
   $ONE = "one";
   $TWO = "TWO";
      
   function test () 
   { 
      $f = array ('ONE', 'TWO'); 
      for ($i = 0; $i < count ($f); ++$i) { 
         GLOBAL ${$f[$i]};  // this line produces parse err
//	 GLOBAL $$f[$i]; // parses OK and is OK.
         print "<p>" . ${$f[$i]} . "\n"; 
      }       
   } 
     
   test ();
     
%>   
May be a documentation error. Cf. http://www.php3.de/manual/variable-variable.php3

"In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write $$a[1] then the parser needs to know if you meant to use $a[1] as a variable, or if you wanted $$a as the variable and then the [1] index from that variable. The syntax for resolving this ambiguity is: ${$a[1]} for the first case and ${$a}[1] for the second"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-12-13 15:46 UTC] joey at cvs dot php dot net
This is fixed in newer versions of PHP.
Thanks for the report!
 [2000-07-18 10:32 UTC] hholzgra at cvs dot php dot net
had already been fixed last year
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 01:01:28 2024 UTC