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 this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC