Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70232 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19423 invoked from network); 20 Nov 2013 11:30:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Nov 2013 11:30:52 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.50 mail-la0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:61573] helo=mail-la0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/86-20870-96D9C825 for ; Wed, 20 Nov 2013 06:30:50 -0500 Received: by mail-la0-f50.google.com with SMTP id el20so7305254lab.9 for ; Wed, 20 Nov 2013 03:30:46 -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=N8YI7EOZkEuL19h9I3FCmhqC38yM3vpHlwq4Ft2rCnc=; b=TPc1fci5yW2QFRJFUwNWWMiXoz7lFilqeQDBwsrZV0o/W8lBOOrBrNk1o71elXa43x g3Ccuv608PwRWyXLsKlNPVuVUxik+BcRCRu+J3TB3KCdoD9IGSWdVyOrco8EswOn2s+1 iFiMuZjWTTLxgz7gnuAM9yD28B7ZeLf9xR+Ljc6ekkbivBt2spoj0l8JrJoZoj5DvWPv uusZA9lYVKVxT1tkac5dJzbTGzK9+HdKh+/BntBgYaWp35HZYaRn6ii+3pOPaqmDCcGS yAamvBXhwpShKLli6ytKzXuSMQcmRZDsCRg76plgCitHn93mLKKu9QViyLg4Co55GrEz eNBA== X-Received: by 10.152.120.135 with SMTP id lc7mr119801lab.38.1384947046607; Wed, 20 Nov 2013 03:30:46 -0800 (PST) Received: from nikita2206-n56vj ([217.174.184.92]) by mx.google.com with ESMTPSA id vz9sm19197900lbb.17.2013.11.20.03.30.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 20 Nov 2013 03:30:46 -0800 (PST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "internals@lists.php.net" References: Date: Wed, 20 Nov 2013 15:30:45 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.16 (Linux) Subject: Re: array_unique optional compare-callback proposal From: inefedor@gmail.com ("Nikita Nefedov") On Thu, 07 Nov 2013 17:24:44 +0400, Nikita Nefedov wrote: > Hello, > > I would like to propose addition of a third (optional) argument for > array_unique which will be callback for comparing elements. > > There's a plenty of usecases for this. For example, what I've been > dealing with can be described like so: > > > $obj1 = new EntityName("asd"); > $obj2 = new EntityName("qwe"); > > $a = [new EntityWrapper($obj1, ...), new EntityWrapper($obj2, ...), new > EntityWrapper($obj1, ...)]; > > // now it can be solved like so: > > $newArray = []; > foreach ($a as $e) { > $newArray[$e->getWrappedObject()->getIdentity()] = $e; > } > > // but with this patch it can be solved with array_unique: > > $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. > > Here's a patch for master branch with implementation of this proposal: > https://gist.github.com/nikita2206/7354392 Hello internals! As long as there were no objections against this proposal I would like to make it into the 5.6. Should this go through all RFC steps or can I just create a PR for it and expect it to be merged?