Hi Patrik

On Thu, May 16, 2024 at 10:31 PM Patrik Václavek <patr...@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 `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

Reply via email to