note 20995 added to ref.variables

From: Date: Wed, 24 Apr 2002 18:53:38 +0000
Subject: note 20995 added to ref.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-29775@lists.php.net to get a copy of this message
There are some problems with your code. You're performing the if(version < 410) comparison every iteration of the loop, but it's not like the version is going to change while the script is running, is it? Wasted processing, inefficient code. Also, I don't see why you're copying everything over and then unsetting the HTTP_xxx_VARs. That again is a huge waste in processing power. What's the point of doing a deep copy of an array if all you're going to do is unset the original?? By using this, you're (technically) making any script that runs this incompatible with php 4.1.0, since $HTTP_xxx_VARS arrays are still valid global variables in php>=4.1.0 It would be better to do this, in my opinion: $vars = Array('GET', 'POST', 'COOKIE', 'SERVER', 'ENV', 'REQUEST', 'SESSION'); $php_version = preg_replace("/[^\d]/", '', phpversion()); if($php_version < 410) { foreach($vars as $var) { $oldname = "HTTP_$var_VARS"; $GLOBALS["_$var"] = & $$oldname; } } Lastly, I don't think that having a variable in the GLOBALS array necessarily makes it a "superglobal" variable. You'll more than likely still have to import it into function scope using the global keyword: function foo() { global $_GET; } After all, any other variable created in global scope still has to be imported into function scope... Take care, Nik -- http://www.php.net/manual/en/ref.variables.php http://master.php.net/manage/user-notes.php?action=edit+20995 http://master.php.net/manage/user-notes.php?action=delete+20995 http://master.php.net/manage/user-notes.php?action=reject+20995

« previous php.notes (#29775) next »