RE: [PHP] PHP newbie question

From: Date: Thu, 11 Jan 2001 08:21:39 +0000
Subject: RE: [PHP] PHP newbie question
Groups: php.general 
Request: Send a blank email to php-general+get-33936@lists.php.net to get a copy of this message
http://www.php.net/manual/language.expressions.php <snip> One last thing worth mentioning is the truth value of expressions. In many events, mainly in conditional execution and loops, you're not interested in the specific value of the expression, but only care about whether it means TRUE or FALSE (PHP doesn't have a dedicated boolean type). The truth value of expressions in PHP is calculated in a similar way to perl. Any numeric non-zero numeric value is TRUE, zero is FALSE. Be sure to note that negative values are non-zero and are thus considered TRUE! The empty string and the string "0" are FALSE; all other strings are TRUE. With non-scalar values (arrays and objects) - if the value contains no elements it's considered FALSE, otherwise it's considered TRUE. </snip> Since variables doesn't need to be declared it's regarded as set when used in an expression... hence $a is evaluated to "", or 0 if compared to numbers, false if compared to boolean. -Jørg -----Original Message----- From: Neil Zanella [mailto:nzanella@cs.mun.ca] Sent: 10. januar 2001 19:33 To: Toby Butzon Cc: PHP General Mailing List Subject: Re: [PHP] PHP newbie question On Wed, 10 Jan 2001, Toby Butzon wrote: > : <?php if (! $a) print "Hello, World!"; // script 2 ?> > > $a evaluates to false, the ! reverses it, and it prints "Hello, World!" What is bothering me is the following: if variables that are not assigned a value were to evaluate to false then since false is the same as the number 1 the following PHP script should print the number 1 but instead prints nothing: <?php if (! $a) print $a; ?> How is this behavior justified? I could not find anything on this in the PHP manual. 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 (#33936) next »