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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 3 = ?
Subscribe to this entry?

 
 [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 May 04 20:01:32 2024 UTC