I've come up with a little not-so-clean but useful function
to avoid checking if a variable is set before reading its
value, specially useful for $_REQUEST and the like:
<?php
function toLocal( $source, &$dest, $default = null )
{
if( isset( $source ) )
$dest = $source;
else
$dest = $default;
}
?>
and then call it this way:
<?php
toLocal( $_REQUEST['item_id'], $item_id, 0 );
?>
It checks wether the variable is set, copies it to a local
variable, and if it wasn't set, it assigns the new variable
a default value, all in one line, preventing you to have to
always check for isset() before trying to read its value.
Gotta call it with because if the variable is not set, then
trying to pass it as an argument will yield a warning.
Petruza.
----
Server IP: 201.216.232.3
Probable Submitter: 24.232.22.244
----
Manual Page -- http:
//www.php.net/manual/en/function.isset.php
Edit -- https://master
.php.net/note/edit/78485
Del: integrated -- h
ttps://master.php.net/note/delete/78485/integrated
Del: useless -- http
s://master.php.net/note/delete/78485/useless
Del: bad code -- htt
ps://master.php.net/note/delete/78485/bad+code
Del: spam -- https:/
/master.php.net/note/delete/78485/spam
Del: non-english --
https://master.php.net/note/delete/78485/non-english
Del: in docs -- http
s://master.php.net/note/delete/78485/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78485
Reject -- https://mast
er.php.net/note/reject/78485
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|