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