php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81440 Missing reflection information for BackedEnums
Submitted: 2021-09-15 11:51 UTC Modified: 2021-09-15 13:43 UTC
From: bpolaszek at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 8.1.0RC1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bpolaszek at gmail dot com
New email:
PHP Version: OS:

 

 [2021-09-15 11:51 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-15 11:59 UTC] nikic@php.net
Are you looking for the getName() method on ReflectionNamedType?
 [2021-09-15 13:09 UTC] bpolaszek at gmail dot com
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!
 [2021-09-15 13:43 UTC] bpolaszek at gmail dot com
-Status: Open +Status: Closed
 [2021-09-15 13:43 UTC] bpolaszek at gmail dot com
Closing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 22:01:33 2024 UTC