note 19311 deleted from language.types.null by danbrown

From: Date: Tue, 19 May 2009 14:21:38 +0000
Subject: note 19311 deleted from language.types.null by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155744@lists.php.net to get a copy of this message
Note Submitter: avbentem at hetnet.nl ---- To extend a bit on tbdavis's comment: :: NULL == NULL is true :: NULL == FALSE is true :: NULL == TRUE is false However: note the implicit type conversions that PHP performs! When using 'identical' instead of 'equal' then both NULL === FALSE and NULL === TRUE yield FALSE. An overview is easily created using something like function evalExpr( $desc ) { echo str_pad($desc , 15) . "--> "; var_dump( eval( "return(" . $desc . ");" )); } Note that even TRUE AND TRUE does not evaluate to a boolean value, and that OR and XOR behave different as well! PHP Version: 4.0.6 false --> bool(false) true --> bool(true) null --> NULL !null --> bool(true) true and true --> int(1) true and false --> int(0) true or true --> int(1) true or false --> int(1) true xor true --> bool(false) true xor false --> bool(true) true == null --> bool(false) true === null --> bool(false) true != null --> bool(true) true !== null --> bool(true) false == null --> bool(true) false === null --> bool(false) false != null --> bool(false) false !== null --> bool(true) null == null --> bool(true) null != null --> bool(false) null === null --> bool(true) null !== null --> bool(false) null or null --> int(0) null xor null --> bool(false) null and null --> int(0) true or null --> int(1) true xor null --> bool(true) true and null --> int(0) false or null --> int(0) false xor null --> bool(false) false and null --> int(0) true < null --> bool(false) true > null --> bool(true) false < null --> bool(false) false > null --> bool(false) 1 + null --> int(1) "text" . null --> string(4) "text" Finally, for those who do not know SQL: in SQL the NULL value is evaluated a bit like "I do not know; it could be anything, like 0, 1, a, b, true, false or even nothing at all". This implies that in SQL NULL == NULL could be interpreted as "could be anything" == "could be something else", which does not yield true! Instead, it yields NULL, which boils down to FALSE in boolean context... Likewise, in SQL: NULL AND TRUE yields NULL NULL OR TRUE yields TRUE NULL AND FALSE yields FALSE NULL OR FALSE yields NULL NULL == TRUE yields FALSE NULL == FALSE yields FALSE a.

« previous php.notes (#155744) next »