Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118978 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20376 invoked from network); 7 Nov 2022 16:50:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Nov 2022 16:50:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4BDC6180539 for ; Mon, 7 Nov 2022 08:50:25 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 7 Nov 2022 08:50:24 -0800 (PST) Received: by mail-lf1-f54.google.com with SMTP id g7so17590070lfv.5 for ; Mon, 07 Nov 2022 08:50:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VvJf/OAxP5X+BV+xtv1tR4e8KougeHKfqJQg+v2e0Z4=; b=N/rlHtOpNlq2sBjHXMsY42g0yT7lZW1qzAc2f9mPWeA1ip2qSsQxFxBFHWbmUmppvX MjT5Aj4Bpx425w+STbXOd+HI+ym8yDoV9fQ2Fa47W5/AubBWvbDlbagKN2lTawMzTk9s WhZcyt668a92vniGAZKh8ZmCxUWlTcMj0Nnis= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VvJf/OAxP5X+BV+xtv1tR4e8KougeHKfqJQg+v2e0Z4=; b=rlD3KZjZVxCaoLShJK7OEphIMtTo/dwynx/nmVan+1hGpaAQNSu4B7Y+xtGoCg3tDW uyefLqDJpSBMBLuFpj8QzgQvVBWIxi0uKCYj9KdOiTuXF1gCHZ9a44Ie2yE5KA3eUMpg ci5qwwzSkpxARQ3M6mEXwPHSx4TeaHVWOiw9bB4WIqqZOhBprFH67juVHzLg9bbxwtX1 mUXtutwHDtjMKb3GJMHnsgdShRLmL3nt23lwGNLN17NHUIV49mj7koWVvNHbETj2PGuI K3DMl++7crQqiMFAIjEQahi06Vyat+XivR9qEMAowS+tumz4Zju071J1ei4k+G50uXb9 xYSw== X-Gm-Message-State: ACrzQf16rRnUrAfBaFddZTjG8QWD5BtxRFRo0rbooOzAo6vTWB43E8r8 9+l2o3BvgB1HuaCZG6zEeYxGnwg7Y7U3rVCt11/oHA== X-Google-Smtp-Source: AMsMyM4JvPG/4Iujlw7zu29bF5YcVdms7Yhk4KcjLvfsBTej+Rxi47gxEe3KTK73+GTSh696v+l6U1iRrPgQ51eNA0A= X-Received: by 2002:ac2:50da:0:b0:4a2:44dc:b820 with SMTP id h26-20020ac250da000000b004a244dcb820mr18904972lfm.316.1667839822975; Mon, 07 Nov 2022 08:50:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Levi Morrison Date: Mon, 7 Nov 2022 09:50:10 -0700 Message-ID: To: Ilija Tovilo Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option From: internals@lists.php.net ("Levi Morrison via internals") A bit off topic, but not entirely: In my opinion, adding another flag isn't the _real_ fix. Any function which does comparisons should take a callable for users to provide any comparison they wish. An iteratively better API would be: function array_unique(list $array, callable(T $a, T $b): int $comparator); Of course, there are other things like instead of using int for `0`, `-1`, `1`, we could have used an enum but we don't have one today. I just mean the core idea of taking callable is better than mucking around with flags while also allowing for custom comparison. Note that it doesn't necessarily prevent optimizations either. For instance, if they had passed `php_compare` or some function which represents `$a <=> $b`, we could identify that just as we identify a specific flag and take an optimized pass. Note that as enums aren't "comparable" directly, we could have provided a custom comparator in this case, no "fix" necessary in core. ---- Of course, this complaining doesn't fix the situation we are in. My first impression is that might be better to provide one or more alternative functions and to deprecate `array_unique`.