Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119501 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3643 invoked from network); 9 Feb 2023 08:56:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Feb 2023 08:56:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D4B591801FD for ; Thu, 9 Feb 2023 00:56:29 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, 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-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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, 9 Feb 2023 00:56:29 -0800 (PST) Received: by mail-wr1-f50.google.com with SMTP id h16so991357wrz.12 for ; Thu, 09 Feb 2023 00:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=38mGfUED3ev9Vy3309Dx8aqx7HLlrk3YAGCrnhNeqlc=; b=nd9FqelAp+xRQpO9VToFRhkpRSleqGxwU+vZFiRLPfTZTas3jjomGjvlhA1+4EyEyS fgce95RMlqTugESXj6zGhkroqmTYZ++LnfSBaHn1JzwKmX7GsT7cOmglqh+Uo6eZGs3L d3ydQCvBMLTo6o5PiQKpkzgLtZhVgyd05MavOKM+0QCWsdsbSMNlho3PjD/pDPWE3sd6 tI9DLr5E2dWSJFaBtrdrm6pVrlfmzOeSx/uO47Zj0ziwAr9l6OifFshqp6/h0jpml8xx TvR/gZRsCd2NqRcjl+gxeIetEqmBXauy+82eYBr88dCovjaZMyaD6V6sk7WH5puXFrJD M7QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=38mGfUED3ev9Vy3309Dx8aqx7HLlrk3YAGCrnhNeqlc=; b=ZKWUSXKkj2McvUdgw3LGkhajX9926kw9TXzh8WCboC+sgPeodN/MRPwnY5RJOwfKKR H+kF0M/0KeGaMpV/JP1UQTY8LsCsHcv/yxxAqwRTPrON5i1t62i3SP4WyyVUm+Phibpj ewWEET1oZXVS4RR4beaXZoT1DCBtFhNbqtOo6AWW0qtG3t3bANA8C2dqfZ1xvjMLflOQ eLIuXLrC5o4KaneHtjMuMTER/9UPN2p0+BFdpKpcc31B+hPwCtAqf5DEnh9bvNCgCMzp 10AEIfOkysgcomIm9OG1407kkpBjmrif8yn8il/sKplck84QicwEvf/eoIhr6W5eERZh t4Bw== X-Gm-Message-State: AO0yUKWFWXsGJwtds1Rfu0vNHxkElJ8JzRHMXrZauYxe3rPWzsFfF3H4 E83j+zKR/4J+V9ye6FuaN+9YO6obKXCilJ7tHj8PPLXFrDk= X-Google-Smtp-Source: AK7set9g2iogIqURxjzdmas786Arz6C571pOHUpDQq2HTpNB3PQ5r1AsrU9luwvHOxnKE8UIAYIf6hTa5lY9GttO08g= X-Received: by 2002:a5d:4988:0:b0:2bf:ae0e:bfed with SMTP id r8-20020a5d4988000000b002bfae0ebfedmr381659wrq.82.1675932987913; Thu, 09 Feb 2023 00:56:27 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 9 Feb 2023 08:56:15 +0000 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="0000000000006978a805f4408ed2" Subject: Re: [PHP-DEV] RFC proposal: values getter in BackedEnum From: rowan.collins@gmail.com (Rowan Tommins) --0000000000006978a805f4408ed2 Content-Type: text/plain; charset="UTF-8" On Thu, 9 Feb 2023 at 01:30, Sergii Shymko wrote: > I'd like to propose an improvement to backed enumerations introduced in > PHP 8.1. > When using enums, it's very common to get all values using the following > boilerplate: > $enumValues = array_map( > fn (\BackedEnum $case) => $case->value, > ExampleEnum::cases() > ); > Since the value is exposed as a public property, there is already a much shorter way of writing this: $enumValues = array_column(BackedEnum::cases(), 'value'); As I pointed out in a StackOverflow answer [ https://stackoverflow.com/a/71235974/157957], you can get the case name the same way, and use different arguments to array_column to get combinations like a look up table from value to name: $nameToValue = array_column(BackedEnum::cases(), 'name', 'value'); Regards, -- Rowan Tommins [IMSoP] --0000000000006978a805f4408ed2--