note 24805 deleted from language.types.boolean by nicos

From: Date: Sat, 12 Oct 2002 01:54:56 +0000
Subject: note 24805 deleted from language.types.boolean by nicos
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-37965@lists.php.net to get a copy of this message
Remember that TRUE and FALSE are no more case sensitive in PHP4. In PHP3 they were predefined constants with the value true and false. So: TRUE === true === True === TrUe FALSE === false === False === FaLsE also: TRUE === (boolean)1 === (boolean)2 FALSE === (boolean)0 === (boolean)"" === (boolean)NULL === (boolean)'' and: TRUE == 1 but TRUE !== 1 FALSE == 0 but FALSE !== 0 and: TRUE === !FALSE === !0 FALSE === !TRUE === !1 === !-1 and: TRUE === empty(FALSE) === empty(0) === empty(0.0) === empty('') === empty(' ') === empty('0') === empty(' 0') === empty('0.0e0') FALSE === empty(TRUE) === empty(1) === empty(-1) === empty(24) === empty(-12.0) === empty('17.0e0') but: TRUE === empty('A1') === empty(NULL) === empty($unset_variable) FALSE === empty('0 ') === empty('00') Globally, the empty() built-in function is identical to the ! operator, except that it avoids a warning on the unset variable; in any case, empty(expression) === @!(expression). The following will generate warnings: if (!$unset_variable) { // generates a warning, but this branch is taken } else { // branch not taken } This similar code generates no warning: if (empty($unset_variable)) { // this branch is taken silently } else { // branch not taken } So you can convert to a boolean any variable silently with this: !empty($variable) // no warning if not set instead of: (boolean)$variable // warning if not set!

« previous php.notes (#37965) next »