php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #74245 No other ways to get all constants from class but using reflection
Submitted: 2017-03-14 10:09 UTC Modified: 2017-03-17 12:22 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: rusbik91 at gmail dot com Assigned:
Status: Closed Package: Performance problem
PHP Version: 7.1.2 OS: Ubuntu 16.04
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: rusbik91 at gmail dot com
New email:
PHP Version: OS:

 

 [2017-03-14 10:09 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-17 12:22 UTC] 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-17 12:24 UTC] 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().
 [2020-02-07 06:06 UTC] phpdocbot@php.net
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
 [2020-02-07 06:06 UTC] phpdocbot@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 07:01:29 2024 UTC