Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79449 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70326 invoked from network); 5 Dec 2014 19:36:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Dec 2014 19:36:39 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wg0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:44444] helo=mail-wg0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/6D-61462-64902845 for ; Fri, 05 Dec 2014 14:36:39 -0500 Received: by mail-wg0-f47.google.com with SMTP id n12so1743492wgh.20 for ; Fri, 05 Dec 2014 11:36:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=aMGCI8cdvPfNiEPuE3kvH5NsWzbJSniHpjPDTvdhjoM=; b=ppnJXu/dTfZ5IZT/BqdHZQzd9hD98Ga1v//drOWoPMgq0sZFHtei+9BvVA+ZOgfS4t GsjXbaXHzGK0KNrGkAgSQfrhyDzJxBZPvm4DXet/g0cP/gUBeR1F4+aJ2EkE4ectll7x 1LYArgBwMXlZKOovr87nk6IutlWKl+1IYaXi47bXOKVaPEHAVC5S6DNYeqdLa1JYO5Ux lyGv6I1xFi533Vn/CmBEumY5jwQe6D2L3RumI5SlyHzy9dcCbKs+yTemJp8nQFnO46vd 2tgHYSJq//B1vvDVMOyVxO97aoW+Lt03R5npfdrdEyvXxGi0b1kxkX2G8WBU2iPpBcRT 9mdw== X-Received: by 10.180.96.227 with SMTP id dv3mr6659435wib.50.1417808194424; Fri, 05 Dec 2014 11:36:34 -0800 (PST) Received: from [192.168.0.148] ([62.189.198.114]) by mx.google.com with ESMTPSA id dg7sm3411489wib.24.2014.12.05.11.36.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Dec 2014 11:36:33 -0800 (PST) Message-ID: <54820922.2030900@gmail.com> Date: Fri, 05 Dec 2014 19:36:02 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: <07b6e60681651c07105d93f6af7f62f3bed9e4ed@mail.qip.ru> <71E539EE-AB67-46D2-826E-CE639D91BE32@ajf.me> In-Reply-To: <71E539EE-AB67-46D2-826E-CE639D91BE32@ajf.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Comparison chain From: rowan.collins@gmail.com (Rowan Collins) Andrea Faulds wrote on 05/12/2014 14:47: >> On 5 Dec 2014, at 14:36, Дмитрий wrote: >> >> Hi! >> >> I followed by https://wiki.php.net/rfc/howto and I would like to propose a concept "comparison chain" to implementing to future PHP versions. >> It would be very usable if PHP can do that in python-style. >> >> Thank for your attension! > Are you saying to allow (1 < x < 2) etc.? That would be nice, although it’s a backwards-compatibility break as currently (1 < x < 2) would do something different, as would, say, ($x == $y == $z). For those of us that don't know Python, an explanation might be handy. From a quick search, this StackOverflow answer sums it up quite nicely, assuming it's correct: http://stackoverflow.com/a/25753528/157957 So, "$a < $b < $c" would be short-hand for "$a < $b && $b < $c". It would short-circuit in exactly the same way, and be extended to any number of comparison operators. The obvious use case is for maths style "is between" notation, e.g. if ( 10 < $total <= 100 ) Is this correct, a) for Python, and b) for what is suggested for PHP? As Andrea notes, it would be a backwards compatibility, although the chances of anyone deliberately using a boolean as operand to a < or > are unlikely, and that's what's currently implied by $x < $y < $z. Perhaps if == was left out of the mix, so that $x == $y == true would evaluate the same way it does now, that might be a working compromise? Regards, -- Rowan Collins [IMSoP]