Req #74245 [Opn]: No other ways to get all constants from class but using reflection
| From: | cmb@php.net | Date: | Fri, 17 Mar 2017 12:22:42 +0000 |
| Subject: | Req #74245 [Opn]: No other ways to get all constants from class but using reflection | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207893@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74245&edit=1
ID: 74245
Updated by: cmb@php.net
Reported by: rusbik91 at gmail dot com
Summary: No other ways to get all constants from class but
using reflection
Status: Open
Type: Feature/Change Request
Package: Performance problem
Operating System: Ubuntu 16.04
PHP Version: 7.1.2
Block user comment: N
Private report: N
New Comment:
> btw, getConstants even does not have documentation, so you see
> how bad it is.
If a function is warned as being currently undocumented, it
doesn't mean that the function is bad or shouldn't be used, but
rather that nobody had the time to properly document it.
Previous Comments:
------------------------------------------------------------------------
[2017-03-14 10:09:09] rusbik91 at gmail dot com
Description:
------------
There is no other ways to get constants list from class but using reflection, that is really slow
(look at example 1).
For properties of class i can do it by using get_object_vars() and it is fast (look at example 2).
Why we need it? PHP lacks of enum construction and we have to implement it via
const.
If we want to get all enum values (like dictionary), so we need to use damned ReflectionClass.
Would be very nice if we can get all const values by quick simple function.
btw, getConstants even does not have documentation, so you see how bad it is.
Test script:
---------------
example 1: http://sandbox.onlinephpfunctions.com/code/e4d114eb2e339be4c6fc5d3a17877d96fbfbcc38
example 2: http://sandbox.onlinephpfunctions.com/code/8d0f8dcc733804fd2f78677bf6e2ac70bd942852
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74245&edit=1