Bug #81457 [Opn->Csd]: Enum: ReflectionMethod->getDeclaringClass() return a ReflectionClass
| From: | git@php.net | Date: | Mon, 20 Sep 2021 13:29:53 +0000 |
| Subject: | Bug #81457 [Opn->Csd]: Enum: ReflectionMethod->getDeclaringClass() return a ReflectionClass | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236710@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81457&edit=1
ID: 81457
Updated by: git@php.net
Reported by: julien dot boudry at gmail dot com
Summary: Enum: ReflectionMethod->getDeclaringClass() return a
ReflectionClass
-Status: Open
+Status: Closed
Type: Bug
Package: Reflection related
Operating System: *
PHP Version: 8.1.0RC2
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikic
Revision: https://github.com/php/php-src/commit/ea11e79a431d4a62088ec8f8d8dd5500217febb5
Log: Fixed bug #81457
Previous Comments:
------------------------------------------------------------------------
[2021-09-18 18:54:35] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81457&edit=1