Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70072 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97976 invoked from network); 10 Nov 2013 08:58:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2013 08:58:08 -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.215.48 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.215.48 mail-la0-f48.google.com Received: from [209.85.215.48] ([209.85.215.48:55091] helo=mail-la0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/D2-14014-E9A4F725 for ; Sun, 10 Nov 2013 03:58:07 -0500 Received: by mail-la0-f48.google.com with SMTP id n7so2059777lam.35 for ; Sun, 10 Nov 2013 00:58:03 -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:cc:content-type; bh=fCbjko7KMiaMUAtjLbeBPJSeMnWqqHkiYWrV069hTus=; b=wclQciGU1T1BFAKx9Yy7Wyn1JDbfQJxLokQSNY/ZuGwKlhIsHTqsCytreRJ3dHll7R MDxK9N830jBUWQuXST0Y5Sd5sTWCk5VOATLC+cJXOUbfs5Cm3QZcF9twu9rKqrTc0aFr GO3POt/RCnXxs5sWjYvMnb5My+HyqLGe77NUJIsUBeb89gZV62e4V45Fpvmlwl228rwQ DduwVoOzmTQ36ch4Pcxo6SSdxaBOTGuucn08dZz+oxfyKEVAeqY+xIsI3VLYZcqE8p/a DOXJSgpOC4FIYAdoKs4qkd4GQ2VWwoKGCrh9yU+XGhsmMS9qrDqnLzX8blahw+UspGK4 ZFaQ== X-Received: by 10.112.145.105 with SMTP id st9mr245799lbb.46.1384073883688; Sun, 10 Nov 2013 00:58:03 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.154.201 with HTTP; Sun, 10 Nov 2013 00:57:23 -0800 (PST) In-Reply-To: <527F3B9B.8040006@sugarcrm.com> References: <527DF228.1080108@sugarcrm.com> <527F3B9B.8040006@sugarcrm.com> Date: Sun, 10 Nov 2013 17:57:23 +0900 X-Google-Sender-Auth: DAy5dPWkGI6bLd-azXv3OmxJFXs Message-ID: To: Stas Malyshev Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b3436962e24c704eaced043 Subject: Re: [PHP-DEV] [RFC] Comparison and conversion inconsistency - need more info From: yohgaki@ohgaki.net (Yasuo Ohgaki) --047d7b3436962e24c704eaced043 Content-Type: text/plain; charset=UTF-8 Hi Stas, On Sun, Nov 10, 2013 at 4:54 PM, Stas Malyshev wrote: > > I'm wandering whether there are functions like min(). It does not > > I would assume anything that does standard comparisons would be working > the same. Doing otherwise would be, yes, inconsistent. So any function > calling compare_function would do the same thing min() does, I imagine. > > > follow basic comparison/conversion rules. min() behavior is nonsense and > > In which case does min() not follow comparison rules as outlined in the > manual? > http://us2.php.net/min Our manual does not have NULL/BOOL type behavior explanations. > > it would be good fixing min() at some point. Not many users will be > > affected, IMO. > > I think this opinion is wrong, and I don't see why these rules are > "nonsense". Some of these rules may not produce result you have > expected, but only because you are comparing types between which natural > comparison does not exist, so we have to choose some behavior which is > arbitrary to a measure. If you look at Python, for example, "None < -1" > is true (or, if you will, True). In Javascript, however, "null < -1" is > false. Both choices have reasons. > > Changing basic comparison rules in the language has very high potential > of affecting users, since virtually every script does comparisons. Of > course, you don't know if anybody ever compares to nulls, but that's not > impossible, so we need to be very careful. I agree your point fully. I think almost all users are using min() only with integer/float and not with bool/null. The bug report might be confusing, but it's is not complaining -1 != false or like, but it's complaining min() is not following standard PHP comparison rules. ----------------------------------- if (-1 < NULL) echo 'NULL is smaller'; else echo '-1 is smaller'; ----------------------------------- returns '-1 is smaller' as all of us expects. However, ----------------------------------- min(-1,null) ----------------------------------- returns NULL. NULL is evaluated as 0 in scalar contexts, but not with min(). NULL wins negative values because of the compare_function() in zend_operators.c. compare_function() treats NULL/BOOL type special way. (i.e Not like expression in 'if' statement or like) That's the reason why I was surprised. I think feasible solution for min() misbehavior is to use new function that uses standard PHP comparison rule. I'll check PHP functions that uses compare_function() later. There may be other array functions use it. I'm not sure if there are 'internal' functions that does not perform comparison(or conversion) non standard way like compare_function(). It's a small change, but it might have big impact for some users. Therefore, if I'll propose this RFC as PHP 6 matter. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --047d7b3436962e24c704eaced043--