Re: Oh, for a "sureset()" (orthogonal to isset())
From: Al (php.newsgroups_at_allysays.com)
Date: 10/31/03
- Next message: Terence: "Passing constructor values to functions in a class"
- Previous message: Al: "Re: PPTs and thumbnails"
- In reply to: weston_at_leary.csoft.net: "Oh, for a "sureset()" (orthogonal to isset())"
- Next in thread: Tom Rogers: "Re: [PHP] Oh, for a "sureset()" (orthogonal to isset())"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: php-general@lists.php.net Date: Fri, 31 Oct 2003 13:58:57 +1100
> function sureset($var) {
>
> if(!isset($var) || empty($var))
> return '';
> else
> return $var;
> }
>
> Of course, when you've got strict checking on, the above doesn't
> work, because if the variable is unset you get caught on the fact
> before the function call happens.
One change will make your code work: just pass the $var argument by
reference, ie. function sureset (&$var) { ...code... }
I wrote a similar function a while ago, with a little added functionality:
function get_if_set ( &$testVar, $falseValue = NULL)
{
if ( isset( $testVar ) )
{
return $testVar;
}
else
{
return $falseValue;
}
}
- Next message: Terence: "Passing constructor values to functions in a class"
- Previous message: Al: "Re: PPTs and thumbnails"
- In reply to: weston_at_leary.csoft.net: "Oh, for a "sureset()" (orthogonal to isset())"
- Next in thread: Tom Rogers: "Re: [PHP] Oh, for a "sureset()" (orthogonal to isset())"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|