Repository navigation
Improvement: get_class_constants and get_object_constants functions - #292
Closed
mwillbanks wants to merge 1 commit into
Closed
mwillbanks wants to merge 1 commit into
mwillbanks wants to merge 1 commit into
Conversation
|
I've always adhered to the standard: try to avoid reflection in production code at all costs... (or cache it like crazy) But this might also diffuse the whole reflection use case ... no? One might even go as far as using these new methods as part of a internal rewrite of reflection and thus making my previous comment about reflection use in production moot :) |
|
+1 |
Author
|
Closing as there does not seem to be enough interest in creating these methods. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Presently the only way to get class constants in a list is to go through the Reflection API: http://php.net/manual/en/reflectionclass.getconstants.php. While the reflection class object is great; it is also far slower than doing this directly in a zend function. Additionally it does not fit in with the current methods:
In my opinion this should be added for consistency as well as to provide a quick[er] and fast[er] way of accessing the constants of a class than having to utilize reflection for a simple call.
There was a previous ticket on this that recommended the ReflectionClass over providing methods: https://bugs.php.net/bug.php?id=43315 However, I still do believe that these functions are needed and are far more efficient.
Speed Differences:
Test Class
Output:
Reflection Class
float(0.079263210296631)
Object Constants
float(0.031561136245728)
Class Constants
float(0.028576850891113)