Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129116 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 4397B1A00BC for ; Thu, 6 Nov 2025 15:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762442809; bh=WCXVLen/cLfSBje/LdActLCm0qXzqqMOhJeRb/s7Dck=; h=Date:From:To:In-Reply-To:References:Subject:From; b=AAVwCSq7r1T2dLZn1+dgcvyEJFKW5rfBsLDDV99lYjS0dYUy1qcVmPef8p8Xhtttx 6CzlnH6dgs6XwbG+Hlzy0+vMYjRKH3HcCt3w3ilh+VHMkCY2+FOtNwYqD6qUUnB3Bh W2vOjTRLjwtGwAQ8FX2RF6s1Fnx7r66DefT7x+dMvqqlEjoZ1OVdWCi37s0fPt5t4k +Q7x2WcixalQE9snDBG4piww0Sy+K63Ij3kc0Xz08bHyzkNhYn25A3FMvawYwgnHvX meEDhIov0Q/fUybmxVE8arc9XsookJ3NE8SwkfMQhlXSCN9VVgXsV0t4/E5EwfHyBA 442HSwmeZnTvQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C602218002E for ; Thu, 6 Nov 2025 15:26:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 6 Nov 2025 15:26:48 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 7C2321D0014A for ; Thu, 6 Nov 2025 10:26:42 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Thu, 06 Nov 2025 10:26:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm3; t=1762442802; x=1762529202; bh=lRZl6Qi0TUBS8LM8MNMnX A5F95jrvvBziLDB0Z5dtrE=; b=X24Juz2VEdgmGmcCDdgwNG35fyvbc0dvBWqcw EAb9fRlJeofa+Civw1rc+97aE4i7SvMybPSxQYUH4rQbDUAmxVWdbQjLZO4qGOi/ dhCm1qsS0RsepGiFFmmlOaS/bPqxKvy6cwQ4l/Cm2B0ZiZiz3/KJl7ag5lWeoaR7 W0nhIKTXe8WhD5cA/anv0rFlqr5y+ha1fABVr3xzqvnN0GFQTARhqfVv7b4G601e HrqeaCAyeUIXiQ5CJMibO0uT+nuOJ6k7mODurJoJNM6n4Z/HBQ8eakZAoq387Syi dFWVowQLNM5kbBTcsFEySi203/4F1Yd3JV3luM+TGDdEiihZA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1762442802; x=1762529202; bh=l RZl6Qi0TUBS8LM8MNMnXA5F95jrvvBziLDB0Z5dtrE=; b=ucJZAAEH+fq/3wmjW QF0U+jSWYvz8BjQlVObR6P00MQd7e4VPxg89Y3C9d0viz1vXTCpacyDfU77gqQst MTGx3G3NFVTotqzZ5O+ZdTb4xb08g4GI1c7QePtM42RrhCVqM5Q1Cd3MctS5egXS sQdvdME7/6meHJRoqLNCqjhDqFfSEKM8XWiJnfXM6OB6BDqpoa9+7UZmzdvP5yS6 tvJzX8ZI8bWnBjkWpFfowYhUQFPKit+FX4NECKZCGDlomVcthTLoX+gmSnxnUAMJ G443ub30ujzDZA/8VW64ckrjVRAZwIheAcmf6HqOnMelBNAwQV0io/HAEFxzviyw vC0rg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddukeejudegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeelfeefleevvdffueejgfegveevgfdthefhveetgeegfeff tdekvefhveegvdehudenucffohhmrghinhepphhhphdrnhgvthdpghhithhhuhgsrdgtoh hmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgr rhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphhtthhopedupdhmoh guvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhp hhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id EFD6570006D; Thu, 6 Nov 2025 10:26:41 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AFNPCnqlwI-o Date: Thu, 06 Nov 2025 09:26:21 -0600 To: "php internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] [Discussion] BackedEnum::values() - Seeking feedback before formal RFC Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Wed, Nov 5, 2025, at 10:09 PM, Mikhail Savin wrote: > Hi internals, > > I would like to propose adding a native values() method to the BackedEnum > interface that returns an array of all backing values. Before creating a > formal RFC, I'm seeking feedback on the concept and approach. > > == Summary == > > The proposal adds: > > interface BackedEnum { > public static function values(): array; > } > > This would allow: > > enum Status: string { > case Active = 'active'; > case Inactive = 'inactive'; > } > > Status::values(); // ['active', 'inactive'] > > == Motivation == > > This pattern is extremely common in the wild. Based on GitHub code search: > > * ~3,860+ direct implementations of this exact pattern > * ~20,000-40,000 estimated real usage when accounting for shared traits > * Used in major frameworks: Symfony core (TypeIdentifier.php), > Laravel ecosystem > * Documented by PHP.net: The manual itself shows EnumValuesTrait as > an example Correction: The manual does not show an EnumValuesTrait that I can find. There is a *comment* in the manual that includes this method, but that's not part of the manual proper, and frankly 90% of comments in the manual should be removed. (cf: https://www.php.net/manual/en/language.enumerations.traits.php#129250) > Common use cases: > * Database migrations: $table->enum('status', Status::values()) > * Form validation: $validator->rule('status', 'in', Status::values()) > * API responses: ['allowed_statuses' => Status::values()] > > == Implementation == > > I have a working implementation with tests: > https://github.com/php/php-src/pull/20398 > > The implementation: > * Mirrors the existing cases() method structure > * Extracts the value property from each case > * Returns an indexed array (0, 1, 2, ...) > * Only available on BackedEnum, not UnitEnum > * All tests pass I am unclear why this is a major advantage over array_column(Status::cases(), 'value'); > == Backward Compatibility - Important Discussion Point == > > This is a breaking change. Enums that already define a values() method > will fail with: > > Fatal error: Cannot redeclare BackedEnum::values() > > Based on ecosystem research: > * ~24,000-44,000 enum instances will break > * All implementations are functionally identical to what's being proposed > * Migration is mechanical: just delete the user-defined method This is a hard-stop. There are hundreds of thousands of packages in the wild that need to support multiple PHP versions. Nearly all packaglist packages (which I presume is where you're drawing the research from; either that or GitHub which will give a similar result set) support at least two consecutive versions, if not 4, 5, or 6. A hard break like this would essentially mean the packages containing those 40,000 enums would be unable to support both PHP 8.5 and 8.6 at the same time. That's simply not an acceptable impact on the ecosystem, regardless of how nice the feature may or may not be. --Larry Garfield