Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129198 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 D54891A00BC for ; Tue, 11 Nov 2025 11:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762861828; bh=fpUBcb1HoIzrBhhllT5COH10APBh/0lzeB/Mv35/b+o=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=LsPNwF8RIqHOUgSi8FkMxt6D9OSTpn99HwDI9Yt3IoITESiHnsdJj46vYSunF5J7n /lDhBBAiNvVJVy6aroHGi2e3aOca7nzw9txgeKckFLgQCgoXa83Lsb6iUPxV1xqzr3 uNruAS81iWtTHluR0HH3SZNuarBPeGaeWw/ihBkoYE/iXUrPIgmGypMLoe4UFujbj0 GCS09onX7xAeftNvQwVQiglLGQHvQ0e0tz3+pWDMtYx+q7y/7FevYjQJvf2ocUijXI N+jT+tfU8G+d5q+/c1kuS9OOTkND35ZBYVMjy8MH46+wuebvmCUCEYnWFGU/m0fuTj SZEQvtSE0551g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DC771180079 for ; Tue, 11 Nov 2025 11:50:27 +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=3.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 11 Nov 2025 11:50:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762861821; bh=fpUBcb1HoIzrBhhllT5COH10APBh/0lzeB/Mv35/b+o=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=MQpTQXaECeeM+W2s9DImbmoWF7MoG8agmjF5Q9l52kQ5WDq6a1dx9GWWkA2+wwcBr GbLbKk6v58YVL6pNKgbBR5LIj0u4zOUgt1TnAG3nLcf3ra/u5Tf2QiPzWtBMg3ITHf vm/wTmHo0rCtPBKNW+NGrZlqAM+1RP44rY9jF3Pl72X4eJHEkDiQGmoM7SCuArFeu9 eDHDAhy3vlfIRB2+CgjFZa2ssRk8JyqUE9tLiQen47jlC+3V5L7KMJlVmrZSDmqJgS 9AyKqFbd8nbsZIKwj7OD62uImlp42n547XfRykmxpI8OB1Slj2AXTouQrN5xPysUz9 mqA0QG0OdxXZw== Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 997FF10C46A; Tue, 11 Nov 2025 11:50:21 +0000 (GMT) Date: Tue, 11 Nov 2025 11:50:21 +0000 (GMT) To: Mikhail Savin cc: Valentin Udaltsov , php internals Subject: Re: [PHP-DEV] [RFC] [Discussion] Add values() Method to BackedEnum In-Reply-To: Message-ID: <34c08e21-8cd1-2e0e-1cca-148d4acc5432@php.net> References: Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-2017921517-1762861821=:3802" From: derick@php.net (Derick Rethans) This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-2017921517-1762861821=:3802 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 11 Nov 2025, Mikhail Savin wrote: > The RFC addresses this by adding "public static function values(): array" > to the BackedEnum interface itself. > With that in place, an enum that defines an incompatible values() will fa= il > at compile time with a normal method-signature incompatibility, exactly > like it would for from()/tryFrom(). >=20 > Here=E2=80=99s a .phpt demonstrating the intended behavior: >=20 > --TEST-- > Backed enums: user-defined values() incompatible with interface signature > --FILE-- > =20 > enum E: string { > case A =3D 'a'; >=20 > // Intentional incompatibility: interface requires array return type > public static function values(): string { > return 'values'; > } > } >=20 > ?> > --EXPECTF-- > Fatal error: Declaration of E::values(): string must be compatible with > BackedEnum::values(): array in %s on line %d Right now, enums can have a "values()" function that can return anything=20 I desire: an array of enum cases, or objects created from these, or=20 strings, or M_PI. If it has to be compatible with =09`BackedEnum::values(): array(int|string)` (which is what your contract demands, even though it can't express the=20 int|string part) Then that is a BC break again. cheers, Derick --8323329-2017921517-1762861821=:3802--