Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70085 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46947 invoked from network); 10 Nov 2013 19:50:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2013 19:50:24 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.172 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.172 mail-lb0-f172.google.com Received: from [209.85.217.172] ([209.85.217.172:47844] helo=mail-lb0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/C0-42270-E73EF725 for ; Sun, 10 Nov 2013 14:50:23 -0500 Received: by mail-lb0-f172.google.com with SMTP id c11so2840843lbj.3 for ; Sun, 10 Nov 2013 11:50:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=1ho6PEjOcecGqd2+7zoY4+QYwByyYadQlgNw1MBP65U=; b=kWMiivQgpK39X3xXQ/FNcjS0QqnU+G2nPnOJjiz8+vNJgSHdCkkOmVWvWTJUs43Ufp RotIZAtC+v3/eIeFBUqYAIH6feDVOD7IktBfpEkbF8wUi/M6mbbC6IlsgolPOSYoNcie PDqFLjNJCFR50qKygBg35hOod6yv259ATrNMf45ZaRGysY46FlB5Bklh3cSKLR5k/SO0 gWWeGQDXM9agTinTZ4zmBoYZ1ikR26NfD3BSmFck8a3b42B4mzUTPhRy2GIdNv+cBB5y PYBuvCw8fGcI51J19Ikzp3IKCl0c6omgAvGf8lYXFswAhE0B5W17j//vQT7voQpgU6Vb gpsw== X-Received: by 10.112.205.34 with SMTP id ld2mr2410674lbc.27.1384113019255; Sun, 10 Nov 2013 11:50:19 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.154.201 with HTTP; Sun, 10 Nov 2013 11:49:38 -0800 (PST) In-Reply-To: References: Date: Mon, 11 Nov 2013 04:49:38 +0900 X-Google-Sender-Auth: FaYY2a6IVNj0TGV7_PBP_KMAJdk Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c3d99ad787bc04ead7ec14 Subject: Re: [RFC] Comparison and conversion inconsistency - need more info From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c3d99ad787bc04ead7ec14 Content-Type: text/plain; charset=UTF-8 Hi all, On Sat, Nov 9, 2013 at 4:12 PM, Yasuo Ohgaki wrote: > I was surprised that wired min() behavior. > The cause of this behavior is in Zend API. > > https://bugs.php.net/bug.php?id=53104 > > So I've made FRC to discuss/document/fix such behavior. > > If anyone know such behavior, please let me know so that I can write them > in the RFC. > > Thank you. > Apparently, I misunderstood the expression evaluation of NULL/FALSE of PHP for my entire PHP life :( The reason why I misunderstood the behavior is [yohgaki@dev ~]$ php -r "var_dump((TRUE < 1));" bool(false) [yohgaki@dev ~]$ php -r "var_dump((TRUE > 1));" bool(false) TRUE always evaluated as 1. I guess I've checked this behavior and made wrong assumption FALSE/NULL is always evaluated as 0, but it's not. [yohgaki@dev ~]$ php -r "var_dump((FALSE == 0));" bool(true) [yohgaki@dev ~]$ php -r "var_dump((FALSE < 0));" bool(false) [yohgaki@dev ~]$ php -r "var_dump((FALSE > 0));" bool(false) [yohgaki@dev ~]$ php -r "var_dump((NULL == 0));" bool(true) [yohgaki@dev ~]$ php -r "var_dump((NULL < 0));" bool(false) [yohgaki@dev ~]$ php -r "var_dump((NULL > 0));" bool(false) FALSE/NULL are evaluated as 0 or less(least). Then the manual could be improved. *Comparison with Various Types* Type of Operand 1Type of Operand 2Result null or string string Convert *NULL* to "", numerical or lexical comparison bool or null anythingConvert to bool , *FALSE* < *TRUE* object object Built-in classes can define its own comparison, different classes are uncomparable, same class - compare properties the same way as arrays (PHP 4), PHP 5 has its own explanation string ,resource ornumber string ,resource ornumber Translate strings and resources to numbers, usual math array array Array with fewer members is smaller, if key from operand 1 is not found in operand 2 then arrays are uncomparable, otherwise - compare value by value (see following example) objectanything object is always greater array anything array is always greater http://php.net/manual/en/language.operators.comparison.php Manual states bool or null anything Convert to bool, FALSE < TRUE [yohgaki@dev ~]$ php -r "var_dump((bool)NULL);" bool(false) I really surprised by myself that I've never bitten by the misunderstanding more than 10 years. Anyway, the manual is better to explain explicitly TRUE always evaluated as 1 while NULL/FALSE is evaluated as 0 or least. Sorry for the confusion. Any comments? -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c3d99ad787bc04ead7ec14--