note 24806 added to language.types.boolean

From: Date: Thu, 29 Aug 2002 01:56:04 +0000
Subject: note 24806 added to language.types.boolean
Groups: php.notes 
Request: Send a blank email to php-notes+get-35952@lists.php.net to get a copy of this message
Despite 1 and 2 can both be converted to a boolean as TRUE, they differ: (1 == TRUE) will be true (2 == TRUE) will be false! In an expression with ==, where there's a numeric value and a boolean, the boolean is promoted to the numeric type and the values are compared. So never perform tests based on the equivalent numeric value of TRUE. Don't write: if ($variable == TRUE)... as the condition would be false if the variable contains something else than a TRUE boolean, or a numeric value different of 1. Simply write: if ($variable)... or: if (!empty($variable))... -- http://www.php.net/manual/en/language.types.boolean.php http://master.php.net/manage/user-notes.php?action=edit+24806 http://master.php.net/manage/user-notes.php?action=delete+24806 http://master.php.net/manage/user-notes.php?action=reject+24806

« previous php.notes (#35952) next »