php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8860 variable array not working
Submitted: 2001-01-23 09:57 UTC Modified: 2002-04-27 14:25 UTC
From: wico at cnh dot nl Assigned:
Status: Closed Package: Feature/Change Request
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: wico at cnh dot nl
New email:
PHP Version: OS:

 

 [2001-01-23 09:57 UTC] wico at cnh dot nl
according to Zeev this should work:

$test = Array("one","two","three","four"); $var = 'test[2]'; echo $$var; /* should echo "three" */

But with it doesn't


Greetz,

Wico

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-23 09:59 UTC] cynic@php.net
no. it will echo contents of $three. if you don't have that variable in current scope, it'll echo null, and, depending on your settings, emit a warning.
 [2001-01-23 10:06 UTC] wico at cnh dot nl
ok and that isn;t working either...
althoug i liked the first more (and still think it should be that way)

so this doesn't work either:

$three = "Grrrr";

echo "Test";
$test = Array("one","two","three","four"); $var = 'test[2]'; echo $$var; /* should echo "three" */

 [2001-01-23 10:07 UTC] wico at cnh dot nl
changed status
 [2001-01-23 10:20 UTC] cynic@php.net
ah, sorry, should've read the report more carefully.
 [2001-01-23 10:25 UTC] stas@php.net
It is definitely not meant to work this way. 'test[2]' is
not a variable name. $test is the variable (array), and
$test[2] is second element of the array. So it belongs to
feature requests.
 [2002-04-27 14:25 UTC] jimw@php.net
you need to use eval() to make something like this unambiguous.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 11 15:01:28 2024 UTC