RE: [PHP-DEV] Proposal for RFC: get_class_constants()

From: Date: Sat, 14 Dec 2013 13:59:35 +0000
Subject: RE: [PHP-DEV] Proposal for RFC: get_class_constants()
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-70638@lists.php.net to get a copy of this message
> -----Original Message-----
> From: Marco Pivetta [mailto:ocramius@gmail.com]
> Sent: Saturday, December 14, 2013 2:51 PM
> To: Lester Caine
> Cc: PHP Internals List
> Subject: Re: [PHP-DEV] Proposal for RFC: get_class_constants()
> 
> On 14 December 2013 14:33, Lester Caine <lester@lsces.co.uk> wrote:
> 
> If it is the only reason you are having to activate reflections?
> Reflections would seem to have a place, but is it really necessary to add
> yet another layer when most of the time it's function is provided better by
> IDE tools anyway? This is a simple example of a current hole in the core
> PHP tools which would help a section of developers who don't need the
> overheads of additional layers.
> 
> @Lester additional layer is still better than *yet another shortcut*.
> 
> Since we already have the feature, introducing another flavor for it seems
> a bit of an overkill, especially if it also has to be maintained.
> 
> Any userland implementation can handle this by also being fast enuff:
> 
> function get_class_constants($className)
> {
>     static $cached = [];
> 
>     if (isset($cached[$className])) {
>         return $cached[$className];
>     }
> 
>     return $cached[$class] = (new \ReflectionClass($class))->getConstants();
> }
> 
> 
> Marco Pivetta
> 
> http://twitter.com/Ocramius
> 
> http://ocramius.github.com/

I am asking myself why PHP hasn't implement ReflectionClass the way Stefan wants to implement
get_class_constants() if his approach is faster. 
I agree that it is somewhat an overkill to have another function for this but maybe Stefan can
instead propose to change the implementation for ReflectionClass and all would benefit from it?
On the other hand, it's quite inconsistent to have get_class_methods(), get_class_vars() but
not get_class_constants(). 




Thread (14 messages)

« previous php.internals (#70638) next »