|
Posted by Norman Peelman on 07/03/07 03:01
arundelo@hotmail.com wrote:
> 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/
>
Or take a look at:
http://us2.php.net/manual/en/function.error-get-last.php
maybe what you're really looking for. For PHP >= 5.2.0
Norm
Navigation:
[Reply to this message]
|