note 68586 deleted from language.types.boolean by bobby

From: Date: Thu, 28 Sep 2006 15:04:23 +0000
Subject: note 68586 deleted from language.types.boolean by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117779@lists.php.net to get a copy of this message
Note Submitter: James Gauth ---- Regarding comments by: bnab at southphlattewebdesign dot com 11-May-2006 12:05 <?php $x; $i = true; echo $i.' I should be true or 1<br><br>'; //value = 1 $i = false; echo $i.' I should be false or 0<br><br>'; //value = '' $i = isset($x); echo $i.' I should be false, as X has no value<br><br>'; //value = '' $x = 'a string'; $i = preg_match('/str/',$x); echo $i.' I should be true on match<br><br>'; //value = 1 $i = preg_match('/trinsg/', $x); echo $i.' I should be false on no match'; //value = 0 ?> The reason $i is an integer on the preg_match() calls is because the return value of preg_match() is an integer of how many matches were made. Since preg_match() terminates after the first match is found, the return value will always either be 0 or 1 integer types (not boolean types). "I beat my head on this one: Depending upon how the boolean value is assigned, it determines the actual boolean value on a FALSE value - integer, empty string etc..." Always check the return type of functions and interpret the value from there, the assumption in the post is that preg_match() returns a boolean type when it does not.

« previous php.notes (#117779) next »