Re: [RFC] [Vote] Type Guards for Classes

From: Date: Thu, 16 May 2024 22:51:18 +0000
Subject: Re: [RFC] [Vote] Type Guards for Classes
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-123326@lists.php.net to get a copy of this message
Hi Patrik On Thu, May 16, 2024 at 10:31 PM Patrik Václavek <PaTrOnY@email.cz> wrote: > > Introduce a new type guard syntax for classes: > > ```php > (Foo) $variable; > ``` > > This syntax will internally perform the following operations: > > 1. Check if $variable is an instance of œ€� > 7Õ8WµL…ÝFoo. > 2. If the check fails, throw a TypeError with a message > indicating the expected and actual types. Note that this feature is covered under the pattern matching RFC with the "Throwing alternative" extension. https://wiki.php.net/rfc/pattern-matching#throwing_alternative In addition to just class types, it would support all other patterns, including scalar types, union types, array shapes, etc. Ilija

« previous php.internals (#123326) next »