Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68521 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99299 invoked from network); 15 Aug 2013 10:49:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2013 10:49:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.44 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.44 mail-qe0-f44.google.com Received: from [209.85.128.44] ([209.85.128.44:52956] helo=mail-qe0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/DE-06453-A42BC025 for ; Thu, 15 Aug 2013 06:49:46 -0400 Received: by mail-qe0-f44.google.com with SMTP id 6so325547qeb.31 for ; Thu, 15 Aug 2013 03:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=FhhZu0gvv7YoHXfJO9Yy9Td++mWvSFuFF6PW27WFlYo=; b=CJfUTid7A72qMhZWy3UTGfTdW+D48gTgQ3EnKIDlEH+3xggI0OnHJP9B/N1Uej6L6v pK9tuzkrRVHUGqbbOuUcXQHdnIbfte5d110ZvFMm2hNtnMQsIBzJVzoFTZhhU+LEo6/k 2AisbcCn0hqwok4mSozW8h1AdvT4w2HNGLfI1QabvfdBjxEhwSxclkPWBnQZYEmdYUoM DUWviMcoU75wrecPuMQNAmRnB2fpy5nkOgKNnNXv60saCPnIgkmI8lPgj6XvFXeykFT+ aAg3jTGrwTxyj4xtf0VpKt/P3J5FxqqNS8LE+604ORn8RiFTAcxWG+mJbEYX0xL1v/Pt D5zQ== MIME-Version: 1.0 X-Received: by 10.229.25.8 with SMTP id x8mr2555858qcb.92.1376563784025; Thu, 15 Aug 2013 03:49:44 -0700 (PDT) Sender: tjerk.meesters@gmail.com Received: by 10.49.67.5 with HTTP; Thu, 15 Aug 2013 03:49:43 -0700 (PDT) In-Reply-To: <24.05.06453.4370A025@pb1.pair.com> References: <24.05.06453.4370A025@pb1.pair.com> Date: Thu, 15 Aug 2013 18:49:43 +0800 X-Google-Sender-Auth: HLy1jd-OhneHXL3X4chll7A5Z-g Message-ID: To: Matthieu Napoli Cc: PHP Internals Content-Type: multipart/alternative; boundary=14dae9d70fa25b91a704e3fa3b92 Subject: Re: [PHP-DEV] array_unique() and object comparison From: datibbaw@php.net (Tjerk Anne Meesters) --14dae9d70fa25b91a704e3fa3b92 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Aug 13, 2013 at 6:15 PM, Matthieu Napoli wrote: > array_unique() is perfect for removing duplicates in a string array, but > not so great for an array of objects. > > SORT_REGULAR was added to compare items without casting them to string. > However it uses the "==" comparison operator. > Unless you have inserted those objects in the array using an identity map, comparisons with == would be the most useful imho. > > I see two improvements: > > - on a short term, improve the documentation to make it explicit that the > "==" operator will be used (the example with "(string) $elem1 === (string) > $elem2" is misleading, "===" should be replaced with "==") > In fact, this is the behaviour if SORT_STRING is given, so perhaps moving that note to where the flags are described makes sense. > > - on a long term, maybe add another option SORT_STRICT (like the $strict > parameter for in_array): that sort would use the strict comparison operator > "===" > +1 for that. In fact, I wouldn't mind having the option to use a custom comparison function (though this function gets called for both the sorting and pruning process). :) > Any thoughts about that? > > Matthieu > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- Tjerk --14dae9d70fa25b91a704e3fa3b92--