Re: PHP newbie question

From: Date: Wed, 10 Jan 2001 16:18:53 +0000
Subject: Re: PHP newbie question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33689@lists.php.net to get a copy of this message
----- Original Message ----- From: "Neil Zanella" <nzanella@cs.mun.ca> To: "PHP General Mailing List" <php-general@lists.php.net> 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: php-general-unsubscribe@lists.php.net : For additional commands, e-mail: php-general-help@lists.php.net : To contact the list administrators, e-mail: php-list-admin@lists.php.net : :

« previous php.general (#33689) next »