php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81438 Enums cannot be used before they are defined
Submitted: 2021-09-14 20:35 UTC Modified: 2021-09-15 08:01 UTC
From: julien dot boudry at gmail dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 8.1.0RC1 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: julien dot boudry at gmail dot com
New email:
PHP Version: OS:

 

 [2021-09-14 20:35 UTC] julien dot boudry at gmail dot com
Description:
------------
This seems to be an inconsistency. The RFC does not say anything about this.

The opposite of what happens to a class.
Working if testEnum is declared before reflection.

Test script:
---------------
<?php

    $objClass = testObject::class; // OK
    $enumClass = testEnum::class; // OK

    new \ReflectionClass(testObject::class); // OK
    new \ReflectionEnum(testEnum::class); // Fatal Error

    //

    class testObject {}

    Enum testEnum {
        case TEXT;
    }



Expected result:
----------------
No error

Actual result:
--------------
PHP Fatal error:  Uncaught ReflectionException: Class "testEnum" does not exist in test.php:7
Stack trace:
#0 test.php(7): ReflectionEnum->__construct()
#1 {main}
  thrown in test.php on line 7

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-14 20:36 UTC] julien dot boudry at gmail dot com
-Summary: ReflectionEnum: Impossible to instantiate in the same way as Classas Class +Summary: ReflectionEnum: Impossible to instantiate in the same way as Class
 [2021-09-14 20:36 UTC] julien dot boudry at gmail dot com
fix title
 [2021-09-14 22:21 UTC] requinix@php.net
-Summary: ReflectionEnum: Impossible to instantiate in the same way as Class +Summary: Enums cannot be used before they are defined -Package: *General Issues +Package: Class/Object related
 [2021-09-14 22:21 UTC] requinix@php.net
ReflectionEnum is fine.
https://3v4l.org/KoUig/rfc#vgit.master

> Working if testEnum is declared before reflection.
Indeed, it looks like enum declarations aren't hoisted as classes are.
https://3v4l.org/ttQL2/rfc#vgit.master
 [2021-09-15 08:01 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2021-09-15 08:01 UTC] nikic@php.net
Early binding is not supported for classes that implement interfaces.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Oct 26 12:03:35 2021 UTC