Enum case value must be compile-time evaluatable

Description

The value of a backed enumeration, string or integer, cannot be build with constant (global or classe). It can only be build with literal values.

This limitation was removed in PHP 8.2.

Example

<?php

enum Foo: string {
    case A = '/' . A;
    case B = '/' . __FILE__;
}

?>

Solutions

  • Upgrade to PHP 8.2.

  • Replace the constants with literal values.