Skip to content

Class String Const cannot be set as Backed Enum Case #8305

Closed
@enobrev

Description

@enobrev

Description

The following code:

<?php
    class A {
        final public const VALUE = 'something';
    }

    enum B: string {
        case C = A::VALUE;
    }

    var_dump(B::C);

Resulted in this output:

PHP Fatal error:  Enum case value must be compile-time evaluatable in /.../enum_const_string.php on line 7

But I expected this output instead:

enum(B::C)

PHP Version

PHP 8.1.4

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions