Skip to content

I want to remove redundant method_exists() check #51283

Discussion options

You must be logged in to vote

The root enum class, UnitEnum, does not have a tryFrom() method. This is only part of the BackedEnum class. So technically the method_exists() check, even if it could be expressed better but probably won't due to Laravel's liberal use of duck-typing in the framework, is required. I guess technically this way one could create a non-backed enum and implement a custom tryFrom() method, but that seems like such an off edge case for PHP as a whole that there's little benefit to the framework allowing this.

Even the generic template on the method leaves the type narrowing out of its declaration, so passing any PHP class string there would be legal, so the usefulness of that is even minimal at b…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@henzeb
Comment options

Answer selected by hrant1020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants