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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: copraonu at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Feb 18 20:01:29 2025 UTC