Reply to Re: isset(), undefined variables, and null

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация