Re: [RFC] [Vote] Type Guards for Classes
| From: | Larry Garfield | Date: | Thu, 16 May 2024 22:58:44 +0000 |
| Subject: | Re: [RFC] [Vote] Type Guards for Classes | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123327@lists.php.net to get a copy of this message | ||
On Thu, May 16, 2024, at 3:31 PM, Patrik Václavek wrote:
> Introduction
> *************
>
> This RFC proposes a new feature in PHP: type guards for classes (or
> interfaces). This feature aims to simplify and standardize the process
> of verifying that a variable is an instance of a specific class,
> enhancing code readability and reducing boilerplate code.
Without commenting on the idea itself, this is just a proposal at the moment. The subject line
implies there's a formal RFC now up for a vote, when there is not even a formal RFC yet. Ie,
please don't abuse the subject line incorrectly. :-)
To comment on the idea itself, I believe Ilija is correct that using pattern matching would be the
better approach here. Right now the RFC suggests $foo as <pattern> would return true or
throw, but "return $foo or throw" would indeed make more sense. And then give us the
entire power of pattern matching. (That RFC will come up formally soon(tm), I swear.)
--Larry Garfield