Req #74245 [Opn->Csd]: No other ways to get all constants from class but using reflection
| From: | phpdocbot@php.net | Date: | Fri, 07 Feb 2020 06:06:23 +0000 |
| Subject: | Req #74245 [Opn->Csd]: 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-225403@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: phpdocbot@php.net
Reported by: rusbik91 at gmail dot com
Summary: No other ways to get all constants from class but
using reflection
-Status: Open
+Status: Closed
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:
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=c957c1054f209bf7785a192036505881d3d4f1a1
Log: Fix #74245: No other ways to get all constants from class but using reflection
Previous Comments:
------------------------------------------------------------------------
[2017-03-17 12:24:51] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=342147
Log: Fix #74245: No other ways to get all constants from class but using reflection
We're not actually fixing this issue, but rather document
ReflectionClass::getConstants().
------------------------------------------------------------------------
[2017-03-17 12:22:40] cmb@php.net
> 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.
------------------------------------------------------------------------
[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