Skip to content

Can't use inherited constant value via 'self' in enum case valueΒ #7821

Closed
@wbars

Description

@wbars

Description

The following code:

<?php

interface I {
    public const DEFAULT_VALUE = 'gambrinus';
}

enum Beer: string implements I {
    // case GAMBRINUS = I::DEFAULT_VALUE;
     case GAMBRINUS = self::DEFAULT_VALUE;
}
var_dump(Beer::GAMBRINUS);

Resulted in this output:

Fatal error: Enum case value must be compile-time evaluatable in /in/Oqm7f on line 9

But I expected this output instead:
No errors, because commented case GAMBRINUS = I::DEFAULT_VALUE produces no error

PHP Version

8.1.1

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions