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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 23:01:32 2024 UTC