Re: Should there be a `get_declared_enums()` function ?

From: Date: Fri, 16 Aug 2024 15:43:59 +0000
Subject: Re: Should there be a `get_declared_enums()` function ?
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-124981@lists.php.net to get a copy of this message
On 16.08.2024 at 17:11, Nicolas Grekas wrote: >> Should a get_declared_enums() function be added ? >> >> Here we go: >> >> function get_declared_enums() { >> $enums = []; >> $exts = get_loaded_extensions(false); >> foreach ($exts as $ext) { >> $re = new ReflectionExtension($ext); >> $classes = $re->getClasses(); >> foreach ($classes as $class) { >> if ($class->isEnum()) { >> $enums[] = $class->name; >> } >> } >> } >> return $enums; >> } > > And here is a one liner: > > function get_declared_enums() { > return array_filter(get_declared_classes(), 'enum_exists'); > } Nice! Are you suggesting that there is no need for get_declared_enums() in the core, since it can be implemented in userland with a single function call? If so, I still would argue that it makes sense to implement the function in the core for (a) consistency, and (b) performance reasons. Cheers, Christoph

« previous php.internals (#124981) next »