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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: drew at elysium dot ltd dot uk
New email:
PHP Version: OS:

 

 [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: Sat Apr 20 02:01:29 2024 UTC