note 35426 deleted from functions by vincent

From: Date: Mon, 01 Sep 2003 14:18:06 +0000
Subject: note 35426 deleted from functions by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55406@lists.php.net to get a copy of this message
Note Submitter: programmer@bardware.de ---- Hi, it seems to me the keyword 'global' not only imports existing global variables to the scope of a function but even ensures the variables exists in any case, which means if the global variable does not exists it is created. I thus wrote two functions: function needGETVar($idx) { global ${"GET".$idx}; if(isset($_GET[$idx])) ${"GET".$idx}=$_GET[$idx]; return; } function needPOSTVar($idx) { global ${"POST".$idx}; if(isset($_POST[$idx])) ${"POST".$idx}=$_POST[$idx]; return; } I pass the index to either of the functions of data I expect to be POSTed or GET'ed (GOT :-) by my script. After calling these functions like: needGETvar('foo'); a Variable $GETfoo exists. Either with the value passed in the URL or empty, but it exists. That means I can compare any value with the data I expect to be passed in the URL without having to check with isset($_GET['foo']) if it really was passed. Bernhard

« previous php.notes (#55406) next »