[Wylug-help] PHP / MySQL development question

Roger Beaumont roger.bea at blueyonder.co.uk
Sat Oct 20 18:23:17 BST 2007


Hi y'all,

Another appeal for assistance.  In my latest job for Lee, the code didn't 
work at least partly because in several places it used $HTTP_GET_VARS (etc) 
without registering them as global.  It seemed to me to be simplest just to 
replace them all with $_GET (etc.), since in that form, they are super-globals.

During the replacement process I came across code like:
------------------------------------------------
// REGISTER GLOBALS
while($vars=each($HTTP_GET_VARS)) {
	$$vars["key"]=$vars["value"];
  	$_SESSION[$vars["key"]]=$vars["value"]; }
	
while($vars=each($HTTP_POST_VARS)) {
	$$vars["key"]=$vars["value"];
	$_SESSION[$vars["key"]]=$vars["value"]; }
// END REGISTER GLOBALS
------------------------------------------------
To make it more opaque, in some files that snippet was commented out, while 
in others it wasn't.  The conspiracy theorist in me suggests that the code 
had been nobbled by commenting this out, but that's not what I'm asking 
about...

I've seen the double $$ construct before, but don't understand it and can't 
find the right place in the docs to check what it does.  When I looked at 
the documentation on predefined variables, that says: "You don't need to do 
a global $_GET; to access it within functions or methods, as you do with 
$HTTP_GET_VARS." - plus the equivalent for the other corresponding arrays. 
  That suggests to me that the whole snippet could have been replaced by:
-----------------------------------------------
global $HTTP_GET_VARS, $HTTP_POST_VARS;
-----------------------------------------------
Simpler, almost certainly faster AND more comprehensible.  But that's not 
really what I'm asking about either...

Assuming that the snippet does do what the comments say, then I think that 
changing all use of $HTTP_GET_VARS to $_GET (etc.) makes the snippet (in 
either form) redundant anyway.

Am I right and are there any issues about my 'solution'?

TIA,

Roger





More information about the Wylug-help mailing list