|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-09-23 12:31 UTC] git@php.net
[2021-09-23 12:31 UTC] git@php.net
-Status: Open
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 19:00:01 2025 UTC |
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