Bug #81457 [NEW]: Enum: ReflectionMethod->getDeclaringClass() return a ReflectionClass

From: Date: Sat, 18 Sep 2021 18:54:35 +0000
Subject: Bug #81457 [NEW]: Enum: ReflectionMethod->getDeclaringClass() return a ReflectionClass
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236676@lists.php.net to get a copy of this message
From: julien dot boudry at gmail dot com Operating system: * PHP version: 8.1.0RC2 Package: Reflection related Bug Type: Bug Bug description:Enum: ReflectionMethod->getDeclaringClass() return a ReflectionClass 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 bug report at https://bugs.php.net/bug.php?id=81457&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81457&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81457&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81457&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81457&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81457&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81457&r=support Expected behavior: https://bugs.php.net/fix.php?id=81457&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81457&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81457&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81457&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81457&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81457&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81457&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81457&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81457&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81457&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81457&r=mysqlcfg

« previous php.bugs (#236676) next »