note 68586 added to language.types.boolean

From: Date: Wed, 02 Aug 2006 15:54:03 +0000
Subject: note 68586 added to language.types.boolean
Groups: php.notes 
Request: Send a blank email to php-notes+get-115488@lists.php.net to get a copy of this message
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. ---- Server IP: 85.116.0.130 Probable Submitter: 62.3.216.18 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.types.boolean.php Edit -- https://master.php.net/note/edit/68586 Del: integrated -- https://master.php.net/note/delete/68586/integrated Del: useless -- https://master.php.net/note/delete/68586/useless Del: bad code -- https://master.php.net/note/delete/68586/bad+code Del: spam -- https://master.php.net/note/delete/68586/spam Del: non-english -- https://master.php.net/note/delete/68586/non-english Del: in docs -- https://master.php.net/note/delete/68586/in+docs Del: other reasons-- https://master.php.net/note/delete/68586 Reject -- https://master.php.net/note/reject/68586 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115488) next »