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

From: Date: Fri, 16 Aug 2024 15:11:29 +0000
Subject: Re: Should there be a `get_declared_enums()` function ?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-124980@lists.php.net to get a copy of this message
> 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; > } > > Porting this to C is left as an excercise for the reader. ;) Hint: > < > > https://github.com/php/php-src/blob/8853cf3ae950a1658054f286117bc8f77f724f00/Zend/zend_builtin_functions.c#L1371-L1399 > > > > Note that the terminating folding marker is backwards. > > > And should the get_declared_classes() function be adjusted > > to exclude > > enums ? > > For reasons that have been stated elsewhere in this thread, I don't > think so. > And here is a one liner: function get_declared_enums() { return array_filter(get_declared_classes(), 'enum_exists'); }

« previous php.internals (#124980) next »