Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129186 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 8E1D81A00BC for ; Mon, 10 Nov 2025 04:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762749663; bh=ahHxiki4cJO/246FXd2tExQmybCKO4lNGkb7ifStAj8=; h=From:Date:Subject:To:From; b=ZN57UP5lsVTjl3yGGPj27h9/NRWT7ObQCc1x0euTlODqm7vhQ6oSYlI605WXBPd4p eaX1Z1pT0KqpIZCxvFr8U7/f8PxZOFZiNZn7Ey5fry9GXpxXYqKdcnUVeBDwJFNn69 1hFtpw8Ixo/9+CuQXRwAqYP0IYQUtEpcBtbYJSK4sNALPoJWR4WnpXqx0wU+ccBlT3 2KD98S8k3LvlotQKH47ZMYUtVVRU4RLqslZwoRkBQMyJiEo6jGdnfu9kgnEQ8BfPhp bQoF09Et9eQMtoUp4WQpABpzqiQwFAckPVlWL29A4w8/Q6FrGs5eF8adR9A8KAi7xc 2tLgjzez+TNsQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 252A7180078 for ; Mon, 10 Nov 2025 04:41:02 +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_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 ; Mon, 10 Nov 2025 04:41:01 +0000 (UTC) Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-b714b1290aeso416109966b.2 for ; Sun, 09 Nov 2025 20:40:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762749655; x=1763354455; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=9sag9DqOQRLLM87Jl92HRbQ8Dj/QPIX9aErm4eTKUZA=; b=cY3dKp0q2temo2DtxDRVEXEEYividP6vaeAjZHhzlkJVIjOsCY5VXdtKSZIX7IpJWy E6119ScEPzQDVT0zgFgunglOvgB0XoPvX3FbV1YkHUmz5eY2QlTml1jgadRRGNeVzq+z ilxY4I9o+CQeoBuUvBKZyMSnAypA9jf/wFqD6QwSZ6RBtfU2jB/zunh2JCExF4Cjxe59 3TzWDG0NKhi4gf98vAJ3n7EHHpGyTgS73t/hSx/EppZBAJ1DovqkDah6nNUktn9HKwiE p+4qie2CfyBadVx9r1+V9bSdYpCixStJDW6UNcA7K9M4y02KWfWNfXYddkl69JzJJunk uDJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762749655; x=1763354455; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9sag9DqOQRLLM87Jl92HRbQ8Dj/QPIX9aErm4eTKUZA=; b=w/85omos0SHrSV0DXvea9HlYBcK9rbmRkexvFAQQYnbLLBDBR9dEhAx7RPBcfDbGY1 iO0ESXmFufWulMs+N6xEfTSOSzYuzxP84JDAdDcWLYJB7n0ZZQ1razXlip7VaDNr8hF1 bctPcen7r97D5m7D7x3MatXTpF/NguQSWY1XaHrDI4VGI1cOAhxOFhYB+dIT9Ih8JdSd UhyhVzk1DyapxseQkfvMdBDKYwL7SRwWt/Iv1H3J7QQhiRpsVD16puNR5epOhWZBU+Dz MEAnp1Og0R1+R9HjgT0UIF1m2Z9cnW7OsZeInQNcZWYYOXBDaepHTQv3Twpf9K9G9pY7 zeCg== X-Gm-Message-State: AOJu0YxTC4aeZpgcGB2B2ohpBGh+VnQlrlJr9Y1RUANgt3zSscJQjeFP byOaY+rIbCqAe1/5qDuKXofZab25zfQUMcO3dcExqV7pmDuwUUHnq92OZ0CLaCYr2T8E43EiBQj 5G1JGlrjOp+nmzBGQglLegQquCaxI0YDtltzIHVo= X-Gm-Gg: ASbGnctWZeUEB4LGVaUxGf9veaBRLu/u/6DQ0m10m7Qffs0ez2OMFyXL215NUl+0jwx K0mDBCplCDvhHnpAwkeQ5W9GrEb+8Nxm+Q8OUvoPYMMhEYvKCj4IOTmxPf1rUl0LvZ2CLH6qX10 HZ8C9wxGO6m6G4w9ySHNK/8oRnwsqjtKNVcxrqoHro9Hg26NMaaCSkYDxkKBXAadiVdMhcTesx8 jGFtJ0vQjtZiOJ4ub5DfnH0Lydl5hKakMGDvrvdGLbiG/ivceq4IGRxRKOcfg== X-Google-Smtp-Source: AGHT+IF4HGiuJHn+2ZFAagayk+W00giTLjTpF02pOpisnkS8BJsvVN2ys49CBsbB0kroov1NbD2NZQ0Zwa3Coys0Mo4= X-Received: by 2002:a17:906:6a08:b0:b70:b83a:73d5 with SMTP id a640c23a62f3a-b72e0591f8dmr668090766b.46.1762749655037; Sun, 09 Nov 2025 20:40:55 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 10 Nov 2025 07:40:43 +0300 X-Gm-Features: AWmQ_blW8KjjfdLtmzq0qgjy8EMoCcXFAYA6jM18WKOTp9KMIXgvBFMC3uFOkWE Message-ID: Subject: [PHP-DEV] [RFC] [Discussion] Add values() Method to BackedEnum To: php internals Content-Type: multipart/alternative; boundary="000000000000043b0106433623d0" From: mikhail.d.savin@gmail.com (Mikhail Savin) --000000000000043b0106433623d0 Content-Type: text/plain; charset="UTF-8" Hi internals, I've created an RFC to add a native values() method to BackedEnum: https://wiki.php.net/rfc/add_values_method_to_backed_enum == Summary == The RFC proposes adding BackedEnum::values() that returns an indexed array of all backing values. The implementation uses conditional registration - the native method is only added when the enum doesn't already define values(), ensuring ZERO backward compatibility breaks. Key points: * Native values() added automatically to new enums * Existing enums with custom values() continue working unchanged * Trait-based implementations are respected * Libraries can maintain their implementation for older PHP versions * Solves boilerplate problem (3,860+ implementations, ~24k-44k real usage) Common use cases: * Database migrations: $table->enum('status', Status::values()) * Form validation: in_array($input, Status::values()) * API responses: ['allowed_values' => Status::values()] == Implementation == Working implementation with conditional registration: https://github.com/php/php-src/pull/20398 The engine checks if values() exists before registering the native version: - User-defined values() present? Use it. - No user-defined values()? Add native implementation. == No BC Breaks == This approach ensures: * Existing code works unchanged (no migration needed) * Immediate benefit for new code (automatic values()) * Gradual adoption possible (libraries can migrate at their pace) Trade-off: Makes values() the only overridable enum method (unlike cases/from/tryFrom). The RFC documents this as a pragmatic choice - solving real problems without forced migrations. == Questions == 1. Is the conditional approach technically sound? 2. Is the API consistency trade-off acceptable given the zero BC breaks? 3. Any concerns with the implementation approach? 4. Should I implement some steps from "Future scope" of the rfc now? Discussion period: 2 weeks minimum before voting. Looking forward to your feedback! Best regards, Savin Mikhail --000000000000043b0106433623d0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi internals,

I've created an RFC to add a nati= ve values() method to BackedEnum:

https://wiki.php.net/rfc/add_values_met= hod_to_backed_enum

=3D=3D Summary =3D=3D

The RFC proposes= adding BackedEnum::values() that returns an indexed array
of all backi= ng values. The implementation uses conditional registration -
the nativ= e method is only added when the enum doesn't already define
values(= ), ensuring ZERO backward compatibility breaks.

Key points:
=C2= =A0 * Native values() added automatically to new enums
=C2=A0 * Existing= enums with custom values() continue working unchanged
=C2=A0 * Trait-ba= sed implementations are respected
=C2=A0 * Libraries can maintain their = implementation for older PHP versions
=C2=A0 * Solves boilerplate proble= m (3,860+ implementations, ~24k-44k real usage)

Common use cases:=C2=A0 * Database migrations: $table->enum('status', Status::va= lues())
=C2=A0 * Form validation: in_array($input, Status::values())
= =C2=A0 * API responses: ['allowed_values' =3D> Status::values()]=

=3D=3D Implementation =3D=3D

Working implementation with con= ditional registration:
https://github.com/php/php-src/pull/20398

The engine check= s if values() exists before registering the native version:
=C2=A0 - Use= r-defined values() present? Use it.
=C2=A0 - No user-defined values()? A= dd native implementation.

=3D=3D No BC Breaks =3D=3D

This app= roach ensures:
=C2=A0 * Existing code works unchanged (no migration need= ed)
=C2=A0 * Immediate benefit for new code (automatic values())
=C2= =A0 * Gradual adoption possible (libraries can migrate at their pace)
Trade-off: Makes values() the only overridable enum method (unlike
ca= ses/from/tryFrom). The RFC documents this as a pragmatic choice -
solvi= ng real problems without forced migrations.

=3D=3D Questions =3D=3D<= br>
1. Is the conditional approach technically sound?
2. Is the API c= onsistency trade-off acceptable given the zero BC breaks?
3. Any concern= s with the implementation approach?
4. Should I implement some steps fr= om "Future scope" of the rfc now?=C2=A0

Discussion period:= 2 weeks minimum before voting.

Looking forward to your feedback!
Best regards,
Savin Mikhail
--000000000000043b0106433623d0--