php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6470 Variable variables with arrays
Submitted: 2000-08-31 11:27 UTC Modified: 2000-08-31 11:57 UTC
From: drew at elysium dot ltd dot uk Assigned:
Status: Closed Package: Other
PHP Version: 4.0.2 OS: RH 6.2 i386
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:
45 + 10 = ?
Subscribe to this entry?

 
 [2000-08-31 11:27 UTC] drew at elysium dot ltd dot uk
Is there any reason why this does not work :-

<?
$array = array("key" => "value");
$key = "[key]";

$variable_variable = "array${key}";

$value = $$variable_variable;

print $value;
?>

The only way around this seems to be eval.  Not good.

Rgds Drew Wells

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-31 11:57 UTC] stas@php.net
$$ syntax can be used for variable names only. $var["key"] is an expression, not variable name. For expressions, you need to use eval (if you refuse to use $$variable_variable[$key]). That is not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 19:01:29 2024 UTC