Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70092 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61006 invoked from network); 10 Nov 2013 21:11:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2013 21:11:55 -0000 Authentication-Results: pb1.pair.com header.from=swhitemanlistens-software@cypressintegrated.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=swhitemanlistens-software@cypressintegrated.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain cypressintegrated.com designates 173.1.104.101 as permitted sender) X-PHP-List-Original-Sender: swhitemanlistens-software@cypressintegrated.com X-Host-Fingerprint: 173.1.104.101 rproxy2-b-iv.figureone.com Windows 2000 SP2+, XP SP1 (seldom 98 4.10.2222) Received: from [173.1.104.101] ([173.1.104.101:56039] helo=rproxy2-b-iv.figureone.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FB/60-58055-A96FF725 for ; Sun, 10 Nov 2013 16:11:55 -0500 Received: from localhost ([216.220.114.66]) by rproxy2-b-iv.figureone.com (Brand New Heavy v1.0) with ASMTP id VGV91751 for ; Sun, 10 Nov 2013 13:11:51 -0800 Date: Sun, 10 Nov 2013 16:11:44 -0500 Reply-To: Sanford Whiteman X-Priority: 3 (Normal) Message-ID: <1337538879.20131110161144@cypressintegrated.com> To: Yasuo Ohgaki In-Reply-To: References: <38311741.20131110152833@cypressintegrated.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: [RFC] Comparison and conversion inconsistency - need more info From: swhitemanlistens-software@cypressintegrated.com (Sanford Whiteman) > TRUE only evaluated as 1 otherwise FALSE. FALSE/NULL evaluated as 0 > or least. This is not helping you understand -- you're trying to create rules and fitting some behavior into them, and then withdrawing your "rules" when they appear to break. What you should be doing is using the actual stated rules of the language.=20 I realize you're excited about correcting something that has confused you for a long time, but you are getting ahead of yourself in trying to say there's something fundamentally wrong with the way PHP works. Try to slow down and read the comparison rules. > That's what we need in document. IMO. =20 We absolutely, positively *do not* need something like this in the docs. > However, this behavior seems weird. > [yohgaki@dev ~]$ php -r "var_dump((FALSE < -100));" =20 > bool(true) > [yohgaki@dev ~]$ php -r "var_dump((FALSE > -100));" > bool(false) =20 > [yohgaki@dev ~]$ php -r "var_dump((TRUE < -100));" > bool(false) > [yohgaki@dev ~]$ php -r "var_dump((TRUE > -100));" > bool(false) =20 > It's really confusing to me :( 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?=20 =E2=80=A2 FALSE is already a bool: use FALSE =20 =E2=80=A2 cast -100 to bool: use TRUE =20 So the effective strict comparison is FALSE < TRUE =20 By the definition of boolean comparison in PHP, this expression must be TRUE. How about TRUE < -100 =20 Compare as booleans? =E2=80=A2 TRUE is a boolean: use TRUE =20 =E2=80=A2 cast -100 to bool: use TRUE =20 So we've got TRUE < TRUE =20 By the definition of non-object comparison in most any language (including PHP), this expression is FALSE. -- S.