|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2002-04-18 16:43 UTC] lux at simian dot ca
 Constants do not appear to be interpreted properly in the following context:
${CONSTANT}
I found this problem with the following code:
<?php
if (PHP_VERSION < '4.1.0') {
  define ('_GET', 'HTTP_GET_VARS');
  // etc.
} else {
  define ('_GET', '_GET');
  // etc.
}
print_r (${_GET});
?>
This should print out the $_GET hash in 4.2.0RC4, but it prints nothing.  A quick check of the _GET constant shows that it does contain the proper value.
I compile php with:
'./configure' '--with-pgsql=shared' '--with-gd' '--with-mysql=/usr/local/mysql' '--with-apxs2=/usr/local/apache2/bin/apxs' '--enable-shmop' '--enable-xslt' '--with-xslt-sablot'
Thanks!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 04:00:01 2025 UTC | 
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); ?>