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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
11 + 19 = ?
Subscribe to this entry?

 
 [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 18 10:01:32 2024 UTC