Re: Re: [RFC] Comparison and conversion inconsistency - need more info

From: Date: Sun, 10 Nov 2013 21:23:14 +0000
Subject: Re: Re: [RFC] Comparison and conversion inconsistency - need more info
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-70094@lists.php.net to get a copy of this message
On Mon, Nov 11, 2013 at 6:11 AM, Sanford Whiteman < swhitemanlistens-software@cypressintegrated.com> wrote: > OK, first throw out EVERYTHING you have assumed to date. > > Now, realize that PHP has a documented rule of comparing booleans to > integers (this rule is found in the "NULL or boolean - to - anything" > part of the page on comparison). > > The rule is: compare as booleans, where FALSE < TRUE. > > So take > > FALSE < -100 > > How do we compare them as booleans? > > • FALSE is already a bool: use FALSE > > • cast -100 to bool: use TRUE > > So the effective strict comparison is > > FALSE < TRUE > > By the definition of boolean comparison in PHP, this expression must > be TRUE. > > How about > > TRUE < -100 > > Compare as booleans? > > • TRUE is a boolean: use TRUE > > • cast -100 to bool: use TRUE > > So we've got > > TRUE < TRUE > > By the definition of non-object comparison in most any language > (including PHP), this expression is FALSE. > Root cause of my misunderstanding is wrong assumption that BOOL/NULL are evaluated as INT, but it's BOOL. Thank you for your time. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#70094) next »