|
Posted by Norman Peelman on 07/03/07 02:49
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
No... !isset($Foo) determines if $Foo is ok to evaluate. If $Foo is not
set or === NULL then $Foo === NULL never gets evaluated. But yes you are
correct in that that part is redundant. Which by the way should have
answered you question at this point. See below.
> $Foo. (That's easy to fix with the @ operator.)
....that only suppresses the error.
> - It gives an incorrect result if $Foo is safe to evaluate
> but has had NULL assigned to it:
>
I assumed that NULL was not an acceptable value for what you were
looking for. Again, see below.
> $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/
>
Try this:
$dump = array_key_exists('Foo',$GLOBALS) ? var_dump($Foo) : 'Not safe to
evaluate.';
should be what you're looking for, No? I'd like to see how your using
this...
Norm
Navigation:
[Reply to this message]
|