Bug #81465 [NEW]: Enum case value must be constant

From: Date: Tue, 21 Sep 2021 22:10:09 +0000
Subject: Bug #81465 [NEW]: Enum case value must be constant
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236735@lists.php.net to get a copy of this message
From: dharman Operating system: PHP version: 8.1.0RC2 Package: Scripting Engine problem Bug Type: Bug Bug description:Enum case value must be constant 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 bug report at https://bugs.php.net/bug.php?id=81465&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81465&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81465&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81465&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81465&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81465&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81465&r=support Expected behavior: https://bugs.php.net/fix.php?id=81465&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81465&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81465&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81465&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81465&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81465&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81465&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81465&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81465&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81465&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81465&r=mysqlcfg

« previous php.bugs (#236735) next »