Req #81440 [Opn]: Missing reflection information for BackedEnums
| From: | nikic@php.net | Date: | Wed, 15 Sep 2021 11:59:48 +0000 |
| Subject: | Req #81440 [Opn]: Missing reflection information for BackedEnums | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236622@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
Updated by: nikic@php.net
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:
Are you looking for the getName() method on ReflectionNamedType?
Previous Comments:
------------------------------------------------------------------------
[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