php.net |  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
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: 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-11 15:55 UTC] rasmus@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 15:01:30 2025 UTC