Re: Revisiting proposal for addition of `get_class_constants()`

From: Date: Thu, 11 Jun 2020 20:39:38 +0000
Subject: Re: Revisiting proposal for addition of `get_class_constants()`
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-110489@lists.php.net to get a copy of this message
On Wed, Jun 10, 2020 at 6:33 AM Troy McCabe <troy.mccabe@gmail.com> wrote: > Hi All, > > With several functions (str_contains(), > str_[starts|ends]_with()) added > for PHP8 to make things more clear, it feels like a good time to revisit > the multiple requests to add get_class_constants(string $class): > array. > This would allow userland code to retrieve constants in the same way as > properties / methods, instead of having to use reflection for constants and > built-in functions for properties / methods. In addition to uniformity, a > bit of fiddling shows close to half the time for 10k executions > > I'm willing to implement if there's interest (curiosity got the best of me > for the aforementioned fiddling) > Could you please explain in more detail *why* we should duplicate existing reflection functionality into free-standing functions? I believe the existence of functions like get_class_methods() is a historical artifact, because they were introduced before Reflection was a thing. Unless there is a strong reason to the contrary, I would prefer reflection functionality to stay inside Reflection... You do mention performance as a benefit, but it's not immediately obvious to me which use-cases are bottlenecked by class constant reflection. Regards, Nikita

« previous php.internals (#110489) next »