php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: julien dot boudry at gmail dot com
New email:
PHP Version: OS:

 

 [2021-09-18 18:54 UTC] julien dot boudry at gmail dot com
Description:
------------
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:
---------------
<?php

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:
----------------
ReflectionEnum
ReflectionEnum

Actual result:
--------------
ReflectionClass
ReflectionClass

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-20 13:29 UTC] git@php.net
Automatic comment on behalf of nikic
Revision: https://github.com/php/php-src/commit/ea11e79a431d4a62088ec8f8d8dd5500217febb5
Log: Fixed bug #81457
 [2021-09-20 13:29 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 12:01:28 2024 UTC