|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81457 Enum: ReflectionMethod->getDeclaringClass() return a ReflectionClass
Submitted: 2021-09-18 18:54 UTC Modified: -
From: julien dot boudry at gmail dot com Assigned:
Status: Closed Package: Reflection related
PHP Version: 8.1.0RC2 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
34 + 35 = ?
Subscribe to this entry?

 [2021-09-18 18:54 UTC] julien dot boudry at gmail dot com
With Enum, ReflectionMethod->getDeclaringClass() return a ReflectionClass object instead of ReflectionEnum.

The RFC is unclear about that. But ReflectionEnum extends ReflectionClass, so the types are compatible and it's more logical.
We are forced to use the enum_exists() function, and rebuild a new ExceptionEnum if we need ReflectionEnum.

Test script:

Enum testEnum {
    case A;
    case B;
    public function foo () {}

$re = new ReflectionEnum(testEnum::class);
$me = $re->getMethod('foo');

echo $me->getDeclaringClass()::class;

echo "\n";

$rc = new ReflectionClass(testEnum::class);
$mc = $re->getMethod('foo');

echo $mc->getDeclaringClass()::class;

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-20 13:29 UTC]
Automatic comment on behalf of nikic
Log: Fixed bug #81457
 [2021-09-20 13:29 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Sep 27 14:01:25 2023 UTC