Skip to content

Cannot use Enums before they are declared #16644

@divinity76

Description

@divinity76

Description

In PHP you can use classes and functions before they're declared, as long as they are parsed, like

<?php
f();
function f(){}
$o = new C();
class C{};

It was surprising that Enums cannot:

<?php
$o = e::a;
enum e{
    case a;
}

https://3v4l.org/I99NU Resulted in this output:

Fatal error: Uncaught Error: Class "e" not found in php-wasm run script:2
Stack trace:
#0 {main}
  thrown in php-wasm run script on line 2

So I wonder, is that intentional or not?

PHP Version

PHP 8.3.13

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