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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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 18 10:01:32 2024 UTC