php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #17017 Can't use variable variables on superglobals within functions and methods
Submitted: 2002-05-05 12:58 UTC Modified: 2002-08-23 21:37 UTC
From: lennart dot mulder at gmx dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1 and higher OS: Any
Private report: No CVE-ID: None
 [2002-05-05 12:58 UTC] lennart dot mulder at gmx dot net
Hello :-)

The definition of a variable variable as superglobal works fine when put in the main coding (i.e. not within a function or method). Example:

<?php 

$aVariable = 'GET'; 
echo ${"_{$aVariable}"}; 

?> 

The system output is: Array

In the next example however, where the same code is put into a function, the resulting output is a error message instead:

<?php 

function aFunction() 
{ 
   $aVariable = 'GET'; 
   echo ${"_{$aVariable}"}; 
} 
aFunction(); 

?> 

The system output is: Notice: Undefined variable: _GET in Bestand.php on line 6.

Also when $_GET has been defined as global (which should not be necessary) this malfunction remains.

Suggested intermediate solution:

<?php 

function aFunction() 
{ 
   $aVariable = 'GET'; 
   echo $GLOBALS["_{$aVariable}"]; 
} 
aFunction();

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-05 13:00 UTC] mfischer@php.net
Known limitation.

I don't know yet if this has been documented already, there's another report about this issue though.

Marking as duplicate for now.
 [2002-05-05 13:12 UTC] mfischer@php.net
Reclassified as documentation problem, updated subject.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 23:01:28 2024 UTC