Posted by Norman Peelman on 07/02/07 02:05
arundelo@hotmail.com wrote:
> gosha bine wrote:
>
>> You could also inspect the symbol table directly via
>> get_defined_vars
>
> Ah yes! (This also occurred to me after my original post.)
>
> $Vars = get_defined_vars();
> if (isset($Foo) || array_key_exists('Foo', $Vars)) {
> // Safe to evaluate $Foo:
> var_dump($Foo);
> } else {
> echo "Not safe to evaluate \$Foo.\n";
> }
>
>> but that's ugly.
>
> Indeed, but not quite as bad as my other solution.
>
> Andrew Hutchings wrote:
>
>> You could use is_null().
>
> Nope, is_null() always tries to evaluate its argument, so an
> E_NOTICE might be emitted.
>
> --
> Aaron
> http://arundelo.com/
>
Easier:
$dump = (!isset($Foo) || $Foo === NULL) ? 'Not safe to evaluate' :
var_dump($Foo);
Norm
[Back to original message]
|