|  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
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:
Solve the problem:
39 - 31 = ?
Subscribe to this entry?

 [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-2021 The PHP Group
All rights reserved.
Last updated: Tue Sep 28 15:03:36 2021 UTC