note 50388 deleted from function.isset by nlopess

From: Date: Sat, 26 Feb 2005 20:08:48 +0000
Subject: note 50388 deleted from function.isset by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-85594@lists.php.net to get a copy of this message
Note Submitter: Luca Jacoponi Reason: useless ---- Is usually checked for PHP5 with register_long_arrays off, and is a very common abit to check also if a http vars is set (using isset()) before having an assigment. I looked at some code (eg: phbb) and this is resolved assigned every time the var. This is a really common function could be used every time we use http vars: <?PHP function getHttp(&$vars, $method) { global ${'HTTP'.$method.'_VARS'}; // PHP5 with register_long_arrays off? if (!isset(${'HTTP'.$method.'_VARS'}) && isset($method)) { ${'HTTP'.$method.'_VARS'} = $method; } do { $key = key($vars); $vars[$key] = isset(${'HTTP'.$method.'_VARS'}["$key"]) ? ${'HTTP'.$method.'_VARS'}["$key"] : '' ; } while (each($vars)); } ?> For use it: <?PHP // We create an array containing the name // of each variable we want use as keys $vars = array('id' => '', 'page' => '', 'sid' => ''); getHttp(&$vars, '_GET'); // Now you can access each value using $vars[$key] echo $vars['id']; ?>

« previous php.notes (#85594) next »