Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94981 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40154 invoked from network); 10 Aug 2016 00:33:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Aug 2016 00:33:25 -0000 X-Host-Fingerprint: 68.118.157.39 68-118-157-39.dhcp.mdsn.wi.charter.com Received: from [68.118.157.39] ([68.118.157.39:4602] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BE/C9-03404-4567AA75 for ; Tue, 09 Aug 2016 20:33:24 -0400 Message-ID: To: internals@lists.php.net References: Date: Tue, 9 Aug 2016 19:33:21 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 68.118.157.39 Subject: Re: Method compare() From: me@stephencoakley.com (Stephen Coakley) On 08/09/2016 12:33 PM, David Rodrigues wrote: > Currently PHP has a method called "version_compare()". Should be great > if we have the same function but to general usage. There are some > implementations on web for that, but I guess that it could be done > natively. > >> compare(mixed $a, mixed $b, string $operator): boolean > > Then I could do something like that: > >> compare(1, 2, '>') === false >> compare('1', 1, '===') === false > > It should be very useful to libraries that expects that user pass an > operator. For instance: > >> $collection->where('id', '>', 5) => compare($id, 5, '>') > > I guess that it could supports all PHP operators: ==, ===, !=, <>, > !==, <, >, <= and >=. > > The spaceship operator does the works too for integers, but not should > works if you expects than $a === $b, or when you expects than $a >= > $b. > See the Comparable RFC for something similar: https://wiki.php.net/rfc/comparable -- Stephen