Bug #81438 [Opn->Wfx]: Enums cannot be used before they are defined

From: Date: Wed, 15 Sep 2021 08:01:58 +0000
Subject: Bug #81438 [Opn->Wfx]: Enums cannot be used before they are defined
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236608@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81438&edit=1 ID: 81438 Updated by: nikic@php.net Reported by: julien dot boudry at gmail dot com Summary: Enums cannot be used before they are defined -Status: Open +Status: Wont fix Type: Bug Package: Class/Object related Operating System: * PHP Version: 8.1.0RC1 Block user comment: N Private report: N New Comment: Early binding is not supported for classes that implement interfaces. Previous Comments: ------------------------------------------------------------------------ [2021-09-14 22:21:14] 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-14 20:36:03] julien dot boudry at gmail dot com fix title ------------------------------------------------------------------------ [2021-09-14 20:35:29] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81438&edit=1

« previous php.bugs (#236608) next »