[prev in list] [next in list] [prev in thread] [next in thread]
List: php-general
Subject: [PHP] Re: Oh, for a "sureset()" (orthogonal to isset())
From: 203.192.141.38
Date: 2003-10-31 2:58:57
[Download RAW message or body]
> 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;
}
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic