Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84164 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87044 invoked from network); 2 Mar 2015 10:53:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Mar 2015 10:53:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:35077] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/E5-48321-61144F45 for ; Mon, 02 Mar 2015 05:53:10 -0500 Received: by wibbs8 with SMTP id bs8so13819656wib.0 for ; Mon, 02 Mar 2015 02:53:07 -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=+aAvTnoDJmmkv2ObOxTeRffnijAY1qU2I6YgxT3moac=; b=VZ807cu1bntlflvq3NUFkCCYz0aS7Dse1PsXJ+LmPiBrVfPAqoIsIZ84qR671cVD3X KV2HqMsA7DhDXa+TpnJHHJTWGmLWiaJdHaOnXXqEhpRBlpSpkaK7gyODKbvi38WpRxNs S8rMQh0eXYLxfUi3q1Jz/cMQNGxmRin2KrRwJr9wfZ0P6zK9r+1emes1/DvE+HrirY6l NFpyktVjFYF+BQx4OHup7rgqUI4hNBqgE2DFi6qQq+nJNhXc65o+m6IWMjP22KdhrCyn fnriQWEYtirhg4RR6dcySdTsm6oi7i1O4pI5SftHwPzqLBgmF2tGh+5gTlZMsBYGqV0I FVFA== X-Received: by 10.180.90.197 with SMTP id by5mr34762091wib.70.1425293587368; Mon, 02 Mar 2015 02:53:07 -0800 (PST) Received: from [192.168.0.136] ([62.189.198.114]) by mx.google.com with ESMTPSA id gm2sm15546180wib.5.2015.03.02.02.53.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 02:53:06 -0800 (PST) Message-ID: <54F440E6.4050908@gmail.com> Date: Mon, 02 Mar 2015 10:52:22 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Feature request and RFC From: rowan.collins@gmail.com (Rowan Collins) Thomas Gielfeldt wrote on 02/03/2015 07:43: > 2015-02-24 17:17 GMT+01:00 Thomas Gielfeldt : > >> Hi internals. >> >> I've made PR proposing a feature request: A new interface Sortable. >> >> https://github.com/php/php-src/pull/1116 >> >> If possible, I would like to create and RFC describing this in more >> detail, and perhaps get a voting on. >> >> Thanks >> >> Br, >> >> Thomas Gielfeldt >> >> > The 2nd PR I made addresses this (https://github.com/php/php-src/pull/1123), > exposing 3 much simpler interfaces depending on what the user wants/needs > to implement, which combined covers all the 11 sort functions. > > Also, the point of this/these interface(s) is to provide the same power > that some of the other SPL interfaces have (Countable, Serializable, > ArrayAccess, Iterator, etc.). That is, using native functions with objects > possessing certain capabilities. I don't think a container should be expected to reimplement something as specific as a case-insensitive natural string comparison; its job should be to do the actual sorting of data. I suggest a single interface with 3 methods: sortValues($cmp_function), sortValuesAssoc($cmp_function), and sortKeys($cmp_function): https://gist.github.com/IMSoP/4ea904203eadf8d5859a This maintains the obvious connection between userland functions and the method called, and keeps the userland implementation much lower on boilerplate. Conveniently, a collection which internally stores data in an array can pass the callback directly to usort/uasort/uksort for a trivial implementation. Obviously, this means more implementation needed on the engine side, in that it needs to expose callback functions for the various different comparisons, but I think that's where the comparison logic belongs. Regards, -- Rowan Collins [IMSoP]