php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24598 $$var doesn't work with $var="GLOBALS";
Submitted: 2003-07-10 18:29 UTC Modified: 2003-07-10 19:27 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: copraonu at hotmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.2 OS: Win32
Private report: No CVE-ID: None
 [2003-07-10 18:29 UTC] copraonu at hotmail dot com
Description:
------------
I needed to get a variable's or array's value when i had it's name stored in another variable. To get it, i used $$var_name; it all functioned as expected until it came across with $GLOBALS


Reproduce code:
---------------
//doesn't work, gets nothing:
$var = "GLOBALS";
$var = $$var;
print_r($var);

//does work: prints $GLOBALS
gettype($GLOBALS);
$var = "GLOBALS";
$var = $$var;
print_r($var);


Expected result:
----------------
i expected output exactly like print_r($GLOBALS)'s

Actual result:
--------------
but got nothing.
I managed to get wanted result when i added
  gettype($GLOBALS);
before the code;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-10 19:27 UTC] sniper@php.net
RTFM: http://www.php.net/variables.variable

(you can't use variable variables with superglobals..)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 10:01:31 2024 UTC