Best practices: `array_find_key` on `Enum::cases`?
| From: | 0xEAB | Date: | Wed, 29 Apr 2026 21:54:38 +0000 |
| Subject: | Best practices: `array_find_key` on `Enum::cases`? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-328815@lists.php.net to get a copy of this message | ||
I’ve written an enum method as follows.
public function getPrefixBitCount(): int
{
return array_find_key(self::cases(), function(CidrMaskIPv4 $value): bool {
return $value === $this;
});
}
Is this usage of Enum::cases() fine?
Can the order of cases in the returned array be relied on?
Can the numeric keys of the returned array be relied on?