Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70245 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63265 invoked from network); 20 Nov 2013 20:16:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Nov 2013 20:16:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.45 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.45 mail-la0-f45.google.com Received: from [209.85.215.45] ([209.85.215.45:60294] helo=mail-la0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 92/81-51208-C981D825 for ; Wed, 20 Nov 2013 15:16:29 -0500 Received: by mail-la0-f45.google.com with SMTP id eh20so7725336lab.18 for ; Wed, 20 Nov 2013 12:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=ZYU3WjqVWi6sa3YQtSn6fT9qavwOf9wCmW3pPQiNuGU=; b=wIUKYuPb671KCb5qcyz1cHruIxGwx1FKFekJR+dAtzwYNkRpqayYQzgpKI+brFCjo9 H5kmoai5ZPLEZsVsSlTf2QEqzHPiLDT9coclq16477HTpwM/TKgd4qiyEg2sewTx8VOe eXc5CRrqipjEsEhFN8ipdpOXhuv7ktlcw7SWQwwkTNSPKKYhKEEh2vA9NXLp6zaUWdHa MUOuwEk2UzeYwV4rNubzsvvhw7u46Jz3OKofSEiKvYfoPwjW17K5ELZcPi+0WMtJpZ8i nJT4ohY61SVTIS5mRaSuUnTJJfScryo9+1v6SYSVBA1q+E/20Hm86+WCpx+zKgbUQmWF I0pQ== X-Received: by 10.152.45.8 with SMTP id i8mr1854227lam.12.1384978585061; Wed, 20 Nov 2013 12:16:25 -0800 (PST) Received: from nikita-pc (128-69-49-145.broadband.corbina.ru. [128.69.49.145]) by mx.google.com with ESMTPSA id l10sm20703336lbh.13.2013.11.20.12.16.24 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 20 Nov 2013 12:16:24 -0800 (PST) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "internals@lists.php.net" , "Stas Malyshev" References: <528D074F.5010206@sugarcrm.com> Date: Thu, 21 Nov 2013 00:16:30 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <528D074F.5010206@sugarcrm.com> User-Agent: Opera Mail/12.16 (Win32) Subject: Re: [PHP-DEV] Re: array_unique optional compare-callback proposal From: inefedor@gmail.com ("Nikita Nefedov") On Wed, 20 Nov 2013 23:02:39 +0400, Stas Malyshev wrote: > Hi! > >>> $newArray = array_unique($a, SORT_USERDEFINED, function ($a, $b) { >>> return $a->getWrappedObject()->getIdentity() - >>> $b->getWrappedObject()->getIdentity(); >>> }); >>> >>> >>> Actually my problem was a little different but you get the idea... And >>> I >>> think there will be even more usecases for this. > > What I notice here is that if we add SORT_USERDEFINED, we need to add it > to all other sorts, otherwise it would be inconsistent - why SORT_* > works for all sort functions but SORT_USERDEFINED works only for one of > them? And that opens a bit of a can of worms because for many array > functions this already exists as u* aliases - usort, array_udiff, etc. > Hi, Actually I have considered implementing another function for this, but there were two things I didn't like: name of the function array_uunique - it just sounds bad and it will cause a lot of mistakes (when you use autocomplete especially), and second - this function will have a lot of copy-pasted stuff from array_unique source (though this is somewhat solvable if I create another function with logic (not exposed to userland)). But what do you think about this signature then: array_unique(array $array, int $flag); array_unique(array $array, Callable $callback); This is, again, seems inconsistent with all other array_u* functions, but calling a function 'array_uunique' is just something I would prefer to avoid.