Req #81440 [Opn]: Missing reflection information for BackedEnums

From: Date: Wed, 15 Sep 2021 13:09:07 +0000
Subject: Req #81440 [Opn]: Missing reflection information for BackedEnums
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236626@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81440&edit=1 ID: 81440 User updated by: bpolaszek at gmail dot com Reported by: bpolaszek at gmail dot com Summary: Missing reflection information for BackedEnums Status: Open Type: Feature/Change Request Package: Class/Object related PHP Version: 8.1.0RC1 Block user comment: N Private report: N New Comment: That's what happens when you trust your IDE too much - I didn't get completion for that method, hence was sure it did not exist!! I'll report that to Jetbrains. Sorry for bothering! Previous Comments: ------------------------------------------------------------------------ [2021-09-15 11:59:48] nikic@php.net Are you looking for the getName() method on ReflectionNamedType? ------------------------------------------------------------------------ [2021-09-15 11:51:34] bpolaszek at gmail dot com Description: ------------ Hello there, Newly introduced enums come with a reflection API so that we can be aware of what "type" of enum we're dealing with. Regarding backed enums, I just noticed that we are not able, given an enum class (as opposed to an enum case), to determine if cases will be string or integers. We can debug that by doing var_dump((new ReflectionEnum(SomeIntegerOrStringBackedEnum::class))->getBackingType()), and the information will be displayed by debugging the corresponding ReflectionNamedType through the name property, but that property unfortunately has no accessors. Could it be public? Use case is for denormalizing from PDO, which can return strings instead of integers depending of user configuration, using BackedEnum::from method, by knowing in advance if the target enum expects an int or a string. Is it something fixable before stable release? Thanks, Ben ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81440&edit=1

« previous php.bugs (#236626) next »