php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #13363 variable variables with arrays
Submitted: 2001-09-18 07:50 UTC Modified: 2002-04-27 16:09 UTC
From: developer at jaaboo dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: all
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: developer at jaaboo dot com
New email:
PHP Version: OS:

 

 [2001-09-18 07:50 UTC] developer at jaaboo dot com
$dynvar = "GLOBALS[first][second]";
echo $$dynvar;

result : nothing , no error and no output!

for arrays stored in variables only to ways are working:

$dynvar = "GLOBALS";
echo ${$dynvar[first][second]};

or more dynamic but more slower!

$dynvar = "<"."?PHP echo \$GLOBALS[first][second]; ?".">";
eval $dynvar;

you can use a variable to store instead of echo!

I think this breaks the rules of assigning variable variables . It must be possible to store the complete call of the array in a variable. 

The Way implemented jet is not praktical!!!!! Real World Tested! There are so much postings in many Forums and Mailinglist with no suggestion . I can't understand this! So i must think this is a BUG! or was forgotten to realize!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-18 08:24 UTC] hholzgra@php.net
$$ is just a shortcut for a lookup in the variable hashtable
of the current namespace ($GLOABLS if outside a function)

so you end up with the equivalent of $GLOBALS["GLOBALS[first][second]"]
which is obviously not supposed to work as a multidimensional array access

IMHO $$ should *not* become to clever aka. complicated

moved to feature requests for now although the amount of
exclamation marks used almost justified bogusification
 [2002-04-27 16:09 UTC] jimw@php.net
indeed, use eval() when this level of indirection is necessary.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 21:01:26 2024 UTC