ID: 16687 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Bogus +Status: Open -Bug Type: Scripting Engine problem +Bug Type: Documentation problem Operating System: Red Hat Linux 7.1 PHP Version: 4.2.0 New Comment:
Reclassified. It should be documented that due the special way super globals are treated the cannot be used with variable variables. Previous Comments: ------------------------------------------------------------------------ [2002-04-19 12:40:50] [EMAIL PROTECTED] True true. Derick (or someone else) mind briefly explaining why this is/has to be different? ------------------------------------------------------------------------ [2002-04-19 11:11:00] [EMAIL PROTECTED] But then why does it work under certain circumstances and not others? Regardless whether intended or not, this is inconsistent behaviour. I also think that having these differences between regular variables and the "superglobals" shouldn't be necessary. If I can't use them in the same contexts as regular variables, then I would personally prefer the $HTTP_*_VARS instead, because you can. I have found my approach to abstracting this difference ($HTTP_*_VARS vs. $_*) between PHP versions to be really beneficial to my scripts. I can abstract them both down to one name, and use a single reference to the appropriate one instead of sticking if statements every time I need to know which one to use. Sorry to keep buggin' ya, but I think this may be a fair enough argument for change. ------------------------------------------------------------------------ [2002-04-19 10:33:59] [EMAIL PROTECTED] You can't use superglobals indirectly, check this: $t = "_GET"; var_dump ($$t); doesn't work neither, and it wasn't supposed to work. However, this does work (because $HTTP_GET_VARS is not a superglobal): $t = "HTTP_GET_VARS"; var_dump ($$t); Derick ------------------------------------------------------------------------ [2002-04-18 19:09:09] [EMAIL PROTECTED] reclassified ------------------------------------------------------------------------ [2002-04-18 17:30:28] [EMAIL PROTECTED] It seems to be happening only under certain contexts. Here is a script that works fine: <?php $test = 'asdf'; define ('_TEST', 'test'); echo 'constant: '; print_r (${_TEST}); echo '<br />direct: '; print_r ($test); ?> And here is code that does not: <?php if (PHP_VERSION < '4.1.0') { define ('_GET', 'HTTP_GET_VARS'); } else { define ('_GET', '_GET'); } class CGI { var $param = array (); function CGI () { global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_POST_FILES; if (${_GET}) { reset (${_GET}); while (list ($k, $v) = each (${_GET})) { if (get_magic_quotes_gpc () == 1) { $this->{$k} = stripslashes ($v); } else { $this->{$k} = $v; } array_push ($this->param, $k); } } else { echo '<br />_GET value: '; print_r (_GET); echo '<br />$_GET value: '; print_r ($_GET); echo '<br />${_GET} value: '; print_r (${_GET}); } } } $cgi = new CGI; echo '<br />$cgi value: '; print_r ($cgi); ?> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/16687 -- Edit this bug report at http://bugs.php.net/?id=16687&edit=1