Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119600 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96569 invoked from network); 23 Feb 2023 09:39:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Feb 2023 09:39:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3032E1804AC for ; Thu, 23 Feb 2023 01:39:16 -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.7 required=5.0 tests=BAYES_05,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-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (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, 23 Feb 2023 01:39:15 -0800 (PST) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-53852143afcso29008827b3.3 for ; Thu, 23 Feb 2023 01:39:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=St1iJi3IQPh8mRsPWjxnTi+3Ow/oryOIkO3edjegvqw=; b=MIGA8fc3iEzAwpr1d69n5zVsY8UYoMCxk0DutpC+VWxhqg3T9MZjVC0ST+beXlVGUk uK/u0YcLR6q3hqGH+Stf/rCs+TC8MTUnFIJ4ut2TD2VeWJhe35c3jAPcnp0yVN+5Vg85 Y+Qi5b7uaNqWrJl/nuCAXJGKJ4RI5VaobowBLMuCOukxRGWdMzdbB0TWiq4OUW0EHmFW YjPRezNTy4cd7mSvjm/8qoJH62y7DSWsU+V8j6A56uwaaByg5MdiJriS/uN9Wgf91kMr b2tU9lhpKQy2zarfjWiojbArOWe4sv47DCW2vZRPjrdbF7tyUiOlPXtsxTlBTSEmkZLB 59ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=St1iJi3IQPh8mRsPWjxnTi+3Ow/oryOIkO3edjegvqw=; b=LDnW74o4jqz628GPvbabbd0m8L1cpep5koerLVi/y5ClWaSG9B66XDswIU94Btt7B+ bQKF0rsbHetVmBStGpB02LEhV9fqNVfzAziO3+LGhHdJ5cnfzRx2guLjBuKMY6E6WW1G OkxmHRu4eQ+34nUU4Azyc0mrnRCCxCktDH5/+tGMjQtfLVn44WMlFbwFkZKmW2LInRsS +AVVLIyqN4VbpdXQ2hwuYMMBY9W7Hi+tTVMe8PHE3/f1gjJ5aIp2volWT17Bmc+AglPx 5P6bqB7134xYsiK+fyd6dlL6TcQKSCoDnHJkKd1PNyI/wtQ7ImNJ3riaedW8EdiLe7P9 AlJQ== X-Gm-Message-State: AO0yUKV3KXJV/F6Cq1v/Ko1m7hITi6AQejMIRIIIGDZIBFGuwy6RNI/f V7JEwpAYegelylW0t1fg3+LvmZU4aSqYklvmnZlGTKyRzXo63gdo X-Google-Smtp-Source: AK7set9wo1Rq6aCa2R6d+5/ZRuBu4RtrR/hgmwbee6ufIw/XEc91JPxnQQyiPpdnQApSKLgcSxg7uTScMOI1EDSClV0= X-Received: by 2002:a81:ae52:0:b0:536:155a:b73d with SMTP id g18-20020a81ae52000000b00536155ab73dmr1923985ywk.2.1677145154849; Thu, 23 Feb 2023 01:39:14 -0800 (PST) MIME-Version: 1.0 Date: Thu, 23 Feb 2023 10:39:03 +0100 Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Subject: RFC idea: array_*(Enum) From: landers.robert@gmail.com (Robert Landers) Hello, internals, Currently, this is an Error: $allowedRoles = [Role::Admin]; $hasRoles = [Role::User, Role::Admin]; if(!empty(array_intersect($allowedRoles, $hasRoles))) doSomething(); This is an error because enums cannot be cast to a string (and trying to make them stringable is not allowed) and many array functions expect something stringable. To work around this limitation, the above example must be rewritten like this: array_uintersect($allowedRles, $hasRoles, fn($l, $r) => $l === $r ? 0 : 1)); I'd like to propose an RFC that allows array functions to accept stringable values and enum values. Any other values (like general objects) would be out of scope. I foresee someone bringing up how the natural order of an enum would be determined. The order will be determined via the same order as Enum::cases() outputs, independent of their backed value (e.g., lexicographical order as defined in the code), thus the order of enum Alpha : int { case B = 1; case A = 0; } would be [ Alpha::B, Alpha::A ]. This is what happens when calling sort([Alpha::A, Alpha::B]) currently, so I hope this won't be an issue. Some example functions that would be impacted by this RFC (I still haven't dug into all the array functions yet): - array_intersect - array_diff - array_unique? (works with SORT_REGULAR, so this might need discussion/exemption) If this has been proposed before, I apologize, as I did search for something like this before proposing it. Robert Landers Software Engineer Utrecht NL