Re: Bug #15810: superglobals does not work with dynamic vars in functions
| From: | Andrey Hristov | Date: | Fri, 01 Mar 2002 15:01:53 +0000 |
| Subject: | Re: Bug #15810: superglobals does not work with dynamic vars in functions | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-80561@lists.php.net to get a copy of this message | ||
Hmmm, I saw that before when I tried to write code which is compatible with all versions of PHP.
Something like
<pre>
<?php
if ((str_replace('.','',phpversion())<410)){
define("__GET","HTTP_GET_VARS");
}else{
define("__GET","_GET");
}
echo phpversion()."\n";
var_dump(${__GET}['some']);
function a(){
var_dump(${__GET}['some']);
echo __GET;
}
a();
?>
Output:
4.1.1
string(2) "aa"
NULL
_GET
----- Original Message -----
From: <goba@php.net>
To: <php-bugs@lists.php.net>
Sent: Friday, March 01, 2002 4:51 PM
Subject: Bug #15810: superglobals does not work with dynamic vars in functions
> From: goba@php.net
> Operating system: win2k
> PHP version: 4.1.0
> PHP Bug Type: Scripting Engine problem
> Bug description: superglobals does not work with dynamic vars in functions
>
> See the attached example. The first print_r() in the
> function does not print out anything, while the second
> prints out the contents of $_GET. I have set $_GET to a
> dummy array to let you test without a server.
>
> Conclusion: dynamic names does not work for superglobals
> in functions (I have also tested them in methods, but
> these handled the same as functions...). Though
> dynamic names work in global scope for superglobals...
>
> <?php
>
> $_GET = array("aa");
>
> $method = "_GET";
> $var = $$method;
> echo "\n$method vars in global scope:\n";
> print_r($var); // prints out the array
>
> function test ()
> {
> $method = "_GET";
> $var = $$method;
> echo "\n$method vars in test func:\n";
> print_r($var); // prints out nothing
>
> echo "\n_GET vars in test func:\n";
> $var = $_GET;
> print_r($var); // prints out the array
>
> }
>
> test();
>
> ?>
> --
> Edit bug report at http://bugs.php.net/?id=15810&edit=1
> --
> Fixed in CVS:
> http://bugs.php.net/fix.php?id=15810&r=fixedcvs
> Fixed in release:
> http://bugs.php.net/fix.php?id=15810&r=alreadyfixed
> Need backtrace:
> http://bugs.php.net/fix.php?id=15810&r=needtrace
> Try newer version:
> http://bugs.php.net/fix.php?id=15810&r=oldversion
> Not developer issue:
> http://bugs.php.net/fix.php?id=15810&r=support
> Expected behavior:
> http://bugs.php.net/fix.php?id=15810&r=notwrong
> Not enough info:
> http://bugs.php.net/fix.php?id=15810&r=notenoughinfo
> Submitted twice:
> http://bugs.php.net/fix.php?id=15810&r=submittedtwice
>
>