Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118953 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79797 invoked from network); 3 Nov 2022 18:53:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2022 18:53:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D21A2180539 for ; Thu, 3 Nov 2022 11:53:55 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-ua1-f49.google.com (mail-ua1-f49.google.com [209.85.222.49]) (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 ; Thu, 3 Nov 2022 11:53:52 -0700 (PDT) Received: by mail-ua1-f49.google.com with SMTP id y20so1452959uao.8 for ; Thu, 03 Nov 2022 11:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nUJwMLzobgkupF5FnWiPLVaecimOoiWFI2IurzbTvH8=; b=SEsHpKsXa0VLaUsONN41iBQRwgAdgyQ9Jm+3Z3famgosZn1+LNQfUGJ+BX6r2Yx6eA FBPsEFkin0j84wqqX7Hz/dUPImHEqhVQoyl517/IvOroCA9Y/K/4zuAGUErKtLEY6p1M KPEXXrL95N7Jcz1qprs2lzKf4DRdqTMwqXBN9ujBfZRusr5OcbD7XUv4gGodY576q/K6 Dt5fy9W+j+8oaWlKI21mBztf2W8rOYwMl5UntMACMDI3ueWxhd6U5IYdEFEjljfsQco1 7AF59ajOrdreBJ5uO8P2qk1Lw+qLYcRahaV1rilzcACZ2yzqmS28BGlQqhHInogUqU3e cI/w== 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=nUJwMLzobgkupF5FnWiPLVaecimOoiWFI2IurzbTvH8=; b=Nx7ASf7fvTZiMjxZdNF+yMu41plI/+aoXKnxDo7OW9T2c5MfO6cFfqGlMKIp3phQJt oxGLQ1WoeNd/blz39/rEWka6wWpEg6W0LOupvWFPkEeQshENuumhKlZI5/5/t//v7PDv lVJsq7+MVsnirejA7hpptjzzER++DD6aKENv3pB9Z+4OO9fgcRKcyHHgXKW9/8FgTc/e rxmRK3vh7zPp3UAzfXQnAgNnWBg7Tg4OWmKz8420tp5xFE87miYUz5eFYlZtIZWeqzVk uZ5LNdthWXWXiaKG0IdhW6UBQZvZz0pCBDeyoVLIZ1UFvOgNHPn9+ktylJ7I20ZnWXQU Q5vg== X-Gm-Message-State: ACrzQf2uOsOKRxaaPUgz0SnRxK9TlaeBg26wXrTZfuZ2YpxLl9QUX9eb UK4IN8jyDJVBu4QBK4XPnJk2rnIC0Fj6Cuu8kDW13bQJVI0OVg== X-Google-Smtp-Source: AMsMyM6aRrK+eXdbK47PmvnkXCxWt4Laq4GjzHSpMpIB6wLJVMmrjoj9JNv+3EaT/hrvtAffvGRzOGC4+WG65gIu+fM= X-Received: by 2002:ab0:2546:0:b0:411:2adf:98ad with SMTP id l6-20020ab02546000000b004112adf98admr15027602uan.72.1667501631764; Thu, 03 Nov 2022 11:53:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 3 Nov 2022 20:53:40 +0200 Message-ID: To: Ilija Tovilo Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option From: someniatko@gmail.com (someniatko) > To solve this, I propose adding an ARRAY_UNIQUE_IDENTICAL option that > can be passed to array_uniques $flags which uses identical operator > (===) semantics. Internally it uses a new hashmap that allows using > arbitrary PHP values as keys to efficiently remove duplicates. This is > slightly over-engineered for this use case. However, this data > structure will be required for implementing ADTs to deduplicate > instances with the same values. This hashmap is a heavily minimized > version of the teds extensions StrictHashMap [1]. As a regular developer, I look from the usage side, not from the implementation side. From such perspective, remembering that filtering unique enums requires this exact flag is somewhat "dirty": on the surface, nothing tells that enums are non-comparable. You will have to memorize yet another PHP quirk, or be able to build a logical chain: - enums are non-comparable by default - enums have no default string value (if not baked by a string) - array_unique internally sorts an array - default flag for array_unique compares the string representations of its items - thus it won't work for enums in a general case This requires deeper knowledge of PHP, which is for sure a valuable skill, but not as wide-spread as we would like to. Most of the devs will first try to use array_unique() with the default flag, perhaps not even knowing about flags existence. Each usage of such a flag will not reveal intent by itself and at least will require a comment for readable codebases. Perhaps an alternative idea is to provide a default string value for enums which are not baked, Nikolas had already brought up this idea earlier.