Posted by arundelo on 07/02/07 16:54
Norman Peelman wrote:
> Easier:
>
> $dump = (!isset($Foo) || $Foo === NULL) ? 'Not safe to evaluate' :
> var_dump($Foo);
Some problems:
- The second operand of the ||-expression is redundant
because if !isset($Foo) is false then $Foo === NULL will
always be false (and vice versa, for that matter).
- Even if that weren't the case, $Foo === NULL evaluates
$Foo before it's determined whether it's safe to evaluate
$Foo. (That's easy to fix with the @ operator.)
- It gives an incorrect result if $Foo is safe to evaluate
but has had NULL assigned to it:
$Foo = NULL;
$dump = (!isset($Foo) || $Foo === NULL)
? 'Not safe to evaluate'
: var_dump($Foo); // Not reached.
echo "$dump\n"; // Prints "Not safe to evaluate" even though
// $Foo is safe to evaluate.
--
Aaron
http://arundelo.com/
[Back to original message]
|