RE: [PHP] Register Globals
| From: | Ford, Mike [LSS] | Date: | Mon, 21 Jul 2003 12:35:04 +0000 |
| Subject: | RE: [PHP] Register Globals | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-156053@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: stfmoreau [mailto:stfmoreau@yahoo.fr]
> Sent: 21 July 2003 13:23
>
> include this code in your header file :
> // _GET
> if (isset($_GET))
> while (list($key, $val) = each($_GET))
> {
> eval ("$".$key." = '".$val."';");
> }
Whoa! Nasty and inefficient!!
I can understand if you decide initially to use a brute-force drop-in
replacement for register_globals, and leave modifying the rest of your code
until later, but really:
(i) Better:
// _GET
if (isset($_GET))
foreach ($_GET as $key=>$val)
{
$$key = $val;
}
(ii) Even better:
// _GET
if (isset($_GET))
extract($_GET);
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211