[php-src] Issue #7726: enums: is_case() function

From: Date: Mon, 06 Dec 2021 17:33:32 +0000
Subject: [php-src] Issue #7726: enums: is_case() function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238220@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7726 Comment Author: damianwadley https://externals.io/message/112626 It looks like there was originally an "is_enum" function on the table to support this but it was a bit too broad: there were concerns that functionality to check if "Foo::Bar" is an enum was a problem because of the automatic autoloading for a string, so that was then moved into a more dedicated enum_exists function. The support for checking if a _value_ was an enum doesn't seem to have survived the process. You can currently check for the [UnitEnum interface](https://wiki.php.net/rfc/enumerations#new_interfaces) using $value instanceof UnitEnum - as long as you have in your head that enum values [are actually objects](https://3v4l.org/EH9qi). Which is why I think adding an "is_enum" is actually a bit odd. It certainly makes sense on the surface, but it's not like enums are a new primitive type, and there aren't "is_traversable"[^1] or "is_throwable" functions to set a precedent for checking special interfaces. Is there a common use case for checking if something is an enum _in a general sense_? Wouldn't most usages be for checking against a particular enum type (if not already type-hinted), in which case instanceof is already the answer? [^1]: There is is_iterable but that's because it supports arrays too.

« previous php.bugs (#238220) next »