Joined November 2013
·
Posted to
PHP get class name without namespace
over 1 year
ago
It was a big surprise to me, but reflection is actually much faster than the other two.
Here is the result:
Method Name Iterations Average Time Ops/second
-------------- ------------ -------------- -------------
testExplode : [10,000 ] [0.0000020221710] [494,518.01547]
testSubstring : [10,000 ] [0.0000017177343] [582,162.19968]
testReflection: [10,000 ] [0.0000015984058] [625,623.34059]
I have to mention that if I run the tests only once (no iterations, but several runs and making an avarage), the substring solution is the winner in speed. (This is probably because reflection is cached)
Actually the original solution is the slowest of all.
Achievements
48 Karma
0 Total ProTip Views
Nephila Komaci
Have at least one original repos where PHP is the dominant language
Walrus
The walrus is no stranger to variety. Use at least 4 different languages throughout all your repos
Charity
Fork and commit to someone's open source project in need
Python
Would you expect anything less? Have at least one original repo where Python is the dominant language
Raven
Have at least one original repo where some form of shell script is the dominant language
Using the CLASS constant generally works, however it fails if used in a child class of a class which uses a trait: