|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9217 Variable Variables not "setting" as expected
Submitted: 2001-02-11 15:52 UTC Modified: 2001-02-11 15:55 UTC
From: laura at freschinfo dot com Assigned:
Status: Closed Package: Variables related
PHP Version: 4.0.4pl1 OS: Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: laura at freschinfo dot com
New email:
PHP Version: OS:


 [2001-02-11 15:52 UTC] laura at freschinfo dot com
Defined two variable variables.  Expected each to have a different value, both ended up with same value. 

$counter = 0;
$$countrycodefinal = "ctrycode" . $counter;
$$aproposfinal = "aproposCitizen" . $counter;
echo ${$countrycodefinal} . "<br>";
echo ${$aproposfinal} . "<p>";

I expected the value of $$countrycodefinal to be "ctrycode0" and the value of $aaproposfinal to be "aproposCitizen0", instead BOTH ended up with the value of "aproposCitizen0".  

I've repeated this several times whenever I use more than one variable variable in the same script.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-11 15:55 UTC]
Looks like you are confused about how variable variables work.

$a = "hello";
$$a = "world";

At this point $hello would be set to "world"

In your example I don't see $countrycodefinal set to anything and thus $$countrycodefinal doesn't make much sense.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Aug 15 05:01:25 2020 UTC