php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #24335 Use of $$var and arrays
Submitted: 2003-06-25 08:58 UTC Modified: 2003-06-26 07:08 UTC
From: steve at oneniltrade dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.3.2 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: steve at oneniltrade dot com
New email:
PHP Version: OS:

 

 [2003-06-25 08:58 UTC] steve at oneniltrade dot com
Description:
------------
I'm trying to use variable variables to build up an array in a recursive function, but this doesn't seem to be possible.

the following short amount of code illustrates the problem.

$str="array";
${$str}[1]="one";
print_r ($$str);
echo "<br>";
print_r ($array);
.............Output..........
Array ([1]=>one)
Array ([1]=>one)

As expected,

However

$str="array[1]";
$$str="One";
print_r ($$str);
echo "<br>";
print_r ($array);
............Output..........
One

No output, ie $array has no value.
Although $str has the value array[1], $$str is not the same as $array[1], as I believe it should be. (Or needs to be to get my function to work)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-26 05:24 UTC] mgf@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You can only use variable variables for the name of the array itself -- you can't specify any subscripts using this mechanism.

I suggest you post the underlying problem you are trying to solve to php-general to see if anyone has any alternative suggestions.
 [2003-06-26 06:39 UTC] steve at oneniltrade dot com
Hi

This may not be a 'bug' as such, but it was submitted as much as a feature request as a bug report, it would be really useful if it did work as i've described (or at least I think so.) Any chance of this feature being added to a future version?
 [2003-06-26 07:08 UTC] derick@php.net
Nope, this will most likely never be implemented.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 16:01:37 2025 UTC