----- Original Message -----
From: "Neil Zanella" <[EMAIL PROTECTED]>
To: "PHP General Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, January 09, 2001 11:55 PM
Subject: [PHP] PHP newbie question


:
: Hello,
:
: I have a question regarding the following 3 one line .php files:
:
: <?php if (! isset($a)) print "Hello, World!"; // script 1 ?>

isset($a) returns false, the ! reverses it to true, and it prints "Hello,
World!"

:
: <?php if (! $a) print "Hello, World!"; // script 2 ?>

$a evaluates to false, the ! reverses it, and it prints "Hello, World!"

: <?php if (! ) print "Hello, World!"; // script 3 ?>

You get a syntax error. PHP's ! operator does _not_ evaluate to any value;
it has to have a value to operate on. Hence, if you just say if (! ), you
get a syntax error... there's nothing for the ! to operate on.

:
: The first script prints the famous words correctly but what baffles
: me is the second script which should be the same as the third script
: since $a is not set and hence should evaluate to nothing, but PHP 3.0.15
: is evaluating ! $a to true instead of giving me a syntax error as in
: script 3. Can someone explain why this is? Does this make the isset()
: built in function redundant in general?

No, this doesn't make isset() redundant. isset($var) will return true if
$var=0, whereas just testing $var would evaluate to false (since it is 0).

TB

:
: Thanks,
:
: Neil
:
:
: --
: PHP General Mailing List (http://www.php.net/)
: To unsubscribe, e-mail: [EMAIL PROTECTED]
: For additional commands, e-mail: [EMAIL PROTECTED]
: To contact the list administrators, e-mail: [EMAIL PROTECTED]
:
:


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to