Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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__;
}

?>

Alternatives

  • Upgrade to PHP 8.2.
  • Replace the constants with literal values.