On 15-8-2024 15:09, Larry Garfield wrote:
On Wed, Aug 14, 2024, at 8:51 PM, Juliette Reinders Folmer wrote:
L.S.,
I just noticed the following, which struck me as weird/inconsistent:
There are four different OO structures in PHP:
1. Classes
2. Interfaces
3. Traits
4. Enums
For all four, an `*_exists()` function is available, i.e.
`class_exists()`, `interface_exists()`, `trait_exists()` and
`enum_exists()` [2].
But only for three out of the four, a `get_declared_*()` function
exists.
There is `get_declared_classes()`, `get_declared_interfaces()`,
`get_declared_traits()`, but no `get_declared_enums()` [2].
I'm aware that enums are internally considered classes and that
`get_declared_classes()` will retrieve them [1], but the same could be
said about interfaces and traits, yet they do have their own
`get_declared_*()` function.
Should a `get_declared_enums()` function be added ?
And should the `get_declared_classes()` function be adjusted to exclude enums ?
I did check the enum RFC [3], but I couldn't find any mention or
discussion about this in the RFC.
Smile,
Juliette
1: https://3v4l.org/0ub6I
2: https://www.php.net/manual/en/ref.classobj.php
3: https://wiki.php.net/rfc/enumerations
Conext: I can't remember the last time I used get_declared_classes() (thanks to
autoloading and class_exists() it's a kinda pointless function), so when we
were working on enums it never occurred to us to think about it. It wasn't a
deliberate decision to omit, as far as I recall.
I think I'd be open to adding it; my concern would be the overlap with
get_declared_classes(), which as you note currently would include enums, and
changing that is a BC break (even if a tiny one that I doubt would impact
anyone).
--Larry Garfield
Thanks for the response. It was exactly a (custom) autoloader situation
which caused me to start wondering about this.