RE: [PHP] Code Advice

From: Date: Wed, 06 Nov 2002 18:54:54 +0000
Subject: RE: [PHP] Code Advice
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123043@lists.php.net to get a copy of this message
At 19:50 06.11.2002, Ford, Mike [LSS] spoke out and said: --------------------[snip]-------------------- >> -----Original Message----- >> From: Kevin Stone [mailto:kevin@helpelf.com] >> Sent: 06 November 2002 18:32 >> >> The method that you have described below is going to produce >> a numerical Key >> which is going to result in several errors. > >Huh? What on earth does this mean? --------------------[snip]-------------------- $get_allow = array('eat','it','all'); This results in an array as [0] => 'eat', [1] => 'it', [2] => 'all' while (list($key,$val)=each($get_allow)) { if (isset($_GET[$key])) $$key = $val; } At execution, $key will hold the values 0,1,2. The last line of the loop will expand to "$0 = $val", "$1 =" $val", "$2 = $val". All of these are invalid identifiers (may not start with a number). The more, it does absolutely not what the coder intended. The correct loop would be while (list($key,$val)=each($get_allow)) { if (isset($_GET[$val])) { global $$val; $$val = $_GET[$val]; } } The key element is not necessary here. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#123043) next »