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
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: 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

Pull Requests

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: Sun Dec 22 10:01:28 2024 UTC