Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129109 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 6D64E1A00BC for ; Thu, 6 Nov 2025 05:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762407355; bh=ufrg3kjVJmKyzxU2R3ls1u6+SDkkvxIGMjY7j8PcRpA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=HHL/8GV0Hvt3JB0XwO8dbIO/R1ARW8/QFTooTFNVwsi1QaBMdvtWANxLO6iUdunfA 4+/EYjqLophzib5thRKfYCazAVF/giJ/hItaxhcojVeKoDFxgLtXp174R7jCBzYEm9 HO2h/CfRtLS8+3a47ymJEnYv6DhRq73wbvKQE2odBSgr0HmH1NcG6yiGx3sFX52FSJ CmEw8doG9gGglQ5MCN6/s+I2js8CmBmetHT3uLKTeUD5+jeq0CQMIfPcE70onRzQ23 Mp5Vv6uh7ohfMu8drr13vX5/wgPpJp2weZ0dfYWDD6nTGVy1JUlzPNQiV9U1W+njyO l7BGQ/ByUymmQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B26F1180072 for ; Thu, 6 Nov 2025 05:35:53 +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=-0.6 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_LOW, RDNS_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mout-p-101.mailbox.org (unknown [80.241.56.151]) (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 05:35:53 +0000 (UTC) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4d29rl2McJz9v05 for ; Thu, 6 Nov 2025 06:35:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mabe.berlin; s=MBO0001; t=1762407335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z0ku6E2/k4atgDAongd1zY1fGrtWd8nCmQfzFKjD16U=; b=d/KMBFM5IucxdoPuu7GQFcdxq2qoLB3NMij0VkU8blAp4yxJ9Kzkhll8d7NIbypEqTeq7y AcBGxz3GpW6vLYjbszoJfOfL4Gg70Z/VOQhJ+qNIfTDtaPMhh56eXoty400i2p63KubtMK 759crcZkrggZ+shHjGj2RP7G7smUbBZIHTL1gLXufqZLDH/nlTYDJ0WoqU/qlMmA18yh1S mYb1dSoJd3oRZVlrovKKdC5Tgly1tl7ArjQ+LIEA8Kz8vT3jp19EoUkjQoLt8fIrIdMpwR A3HFUgixzgKARErfn35pDVVW3I0gV/Sb3sOCHXzIn8lUB+gnUoEdY/FL5BJo2A== Message-ID: Date: Thu, 6 Nov 2025 06:35:34 +0100 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [Discussion] BackedEnum::values() - Seeking feedback before formal RFC To: internals@lists.php.net References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: marc@mabe.berlin ("Marc B.") Hi Savin, Thanks for sharing your idea. On 06.11.25 05:09, 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 > > Common use cases: >   * Database migrations: $table->enum('status', Status::values()) >   * Form validation: $validator->rule('status', 'in', Status::values()) >   * API responses: ['allowed_statuses' => Status::values()] I agree, this is a common feature I would like as well. > > == 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 > > The break is justified because: > >   1. Behavior is unchanged - native implementation does exactly what users >      already implemented >   2. Migration is trivial - simply remove the redundant method >   3. Precedent exists - PHP 8.1 native enums broke myclabs/php-enum >      (4.9k stars) similarly >   4. Long-term benefit - standardization, discoverability, elimination >      of boilerplate >   5. No alternative - virtual properties are technically infeasible; >      different name doesn't match community expectations Here I don't agree! PHP application especially libraries and frameworks very often have to support multiple PHP versions. They can't just remove an already implemented function and drop support for all previous PHP versions at once. So either, the new function will not be final - to allow getting overwritten by current implementations - in this case you would need to run another analytics to check for naming clashes with different incompatible signature or behavior. Or it needs to kind of deprecation period or another name. Just my 2 cents Marc