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

Reply via email to