Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129115 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 32AF51A00BC for ; Thu, 6 Nov 2025 14:07:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762438028; bh=gmkQUmBs2kyqklLCRjUVn/tJKWd/A/X9hRc+Abr1r+o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=aC4PktfZ1VnamCqXB/Ca5QduHBvLHd+sFhhTHc6XCeUCfnUxuUsSrmATia+c3i9HW kgW7SEAWXk0eadQ/s+zd/bSTK8Bg0i3fYuL8mGMQkDQ+cottoZGMoWYzHU6Rxui/Wa A0EZXh2MRrPciCNZTU0f91cA9PdII9N3o6UPpcG7kPL8cvoZi7htwcLkRjF3Uq5l59 k/pOb/MpqXpwHwZ1/IiWvpeV8+bdqsyMiyFVkJIV6VKuzfMLW+3I00lxMzbaMyfPXd W8w56je6o8MPsLMXDm8Od68QuLMgF1xYp8sRDeSTxz2d2JqfGSo1TgurJE5yNCvBpp L43zVUbJSzhlA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DBD07180072 for ; Thu, 6 Nov 2025 14:07:07 +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.1 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 14:07:04 +0000 (UTC) Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-375eff817a3so9235531fa.1 for ; Thu, 06 Nov 2025 06:06:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762438018; x=1763042818; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=tzj+t0zJaADkQ1dJdKpN87GHyhMUF7iG8E03+01Dzo8=; b=ZbcokZPD70TI+O4v/vveqN8lngeumP0N/0QCvUUJlbBBN96+4+vdATLUOOvswgky5d 57roAldWZHBpGs2iKM+ZDQfXzWt3FCQ4OrM9HJ+Gd13GmGoyzSVfZMs5xgphKkkfqUbH NC9b7wxTxFMA6zuA8hhnPAh2bb1Bv2R4BsWMoJLzzXt7LMw9EqvJJGXxMjHoW3QxlBHX EIKqZS0eeMcZ3RT1i4XRrWGkYkobDJeDC09RV0B19yQaE2vpzHR1O2Sqg/Rm26FsegF+ i3pZrx3aubn+oro5esy/6Uvy5N61p8d/1SYmTPg/4Yw+KH+N5N3agEsZiMgX/KzsKYvi lugQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762438018; x=1763042818; 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=tzj+t0zJaADkQ1dJdKpN87GHyhMUF7iG8E03+01Dzo8=; b=a3O/z+502ZsyDIDZVzcg3I4XuKhHg34t1CMx6427jklEoeNrrEAknjw4oQ+Ehj0dzg TjBjlGysD7M45aRsN0YtHdGCKVPRKTlEvN//PU0+nE0w19uksGuM3XWLirZwgcwzUtgN OJDJulBBZeKo9KdeJIU1txSH9MNjN+Grux20YxJQoHyOihvqfX1cxCzR+2Kqgf6xIhOf F6WxVVff63k6k9hNORV8Vea8B8qSWp5JSMODce3F7MW9+Miw+H4MFZJZt53x2HwSq2kl oRYyTl1b+2r22qF7ZP4p92tsMa+PET+QmxinJgSso4KCk4seZzVc3PaAquy8EW1QICm/ TcIA== X-Gm-Message-State: AOJu0YzyJy2VVIvAwNBfi/l3iJnNhbL3qGQa3XlJLo81X/AQWpG7tipu XPulSjNP3Gwkwnt6VLptmVKRHdqsB9Mej/d6rUcqrTswp8q4X5zr4ZkPz7M25Yk+MonpQCa2TbD zOeLgJqVwVo/qFF3oWTO8q2Me4Skq94ZoOA== X-Gm-Gg: ASbGncvHr+Trwf4CyjF1leQ8ZqUgID1qFBcZoA5SOKvzrZfFmorkd1rczhEP5JK+HM6 Y8+tjOONSWwoYY/dGv6nLX5r9sB9jvvrcofwslLKYllpvrL0lHC3Md+5DMVv63+KFS/r6+Esqsb f+6Pi0YliWJbcrO4o1GQ6xvKU3e8vtjwy1flH5LvXsR2PkeiMd8j4u3YN8JZaEeHe5xHRYokMhS sb8W6FKRrS4K9lZbTfLtzy2Zg4IC/aFfyfVazS/dMILR1oBbWOkv4NxFDoOWbUZYpXT0BM= X-Google-Smtp-Source: AGHT+IEPyHIE8HwBdjTLrt/U0socwNqEhg8cK3xfLNE4zSPyn9a9EdDyDchtPXkCLYTjzqlGzJ/zDUu1HDggvScHy9E= X-Received: by 2002:a05:651c:32d:b0:37a:41d2:5880 with SMTP id 38308e7fff4ca-37a513e5dd2mr17442671fa.16.1762438017557; Thu, 06 Nov 2025 06:06:57 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 6 Nov 2025 14:06:46 +0000 X-Gm-Features: AWmQ_bmo2lng6zI5B2fWsDY0DbQw6mcvnKTuXULNCb5uD0UnaytDGDpmIWfeyUs Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] BackedEnum::values() - Seeking feedback before formal RFC To: "Marc B." Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: tekiela246@gmail.com (Kamil Tekiela) On Thu, 6 Nov 2025 at 05:35, Marc B. wrote: > > 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 I think it would be ok to break it but only in a major version like PHP 9. No deprecation needed.