Bug #81465 [Opn->Csd]: Enum case value must be constant

From: Date: Thu, 23 Sep 2021 12:31:55 +0000
Subject: Bug #81465 [Opn->Csd]: Enum case value must be constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236774@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81465&edit=1 ID: 81465 Updated by: git@php.net Reported by: dharman@php.net Summary: Enum case value must be constant -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem PHP Version: 8.1.0RC2 Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikic Revision: https://github.com/php/php-src/commit/a942b284e6f1c28d98c03db3fdb9bf97bb74e2e7 Log: Fixed bug #81465 Previous Comments: ------------------------------------------------------------------------ [2021-09-21 22:10:09] dharman@php.net Description: ------------ When testing enums in 8.1 I tried to assign a constant value to a backed enum. I got a message saying that the value should be constant. That's very misleading. The RFC states: "Equivalent values must be literals or literal expressions. Constants and constant expressions are not supported. That is, 1+1 is allowed, but 1 + SOME_CONST is not. This is primarily due to implementation complexity. (See Future Scope below.)" I think the message should say "Enum case value must be a literal or a literal expression" or constants should be allowed just like they are in normal classes. Test script: --------------- <?php const A = 'foo'; class Suit { const Heart = A; } enum Suit: string { case Heart = A; } Expected result: ---------------- No fatal errors or warnings Actual result: -------------- Fatal error: Enum case value must be constant in /in/sj7b4 on line 10 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81465&edit=1

« previous php.bugs (#236774) next »