On Tuesday, March 29th, 2022 at 12:55 AM, Karoly Negyesi <karoly@negyesi.net> wrote:
> Hi,
>
> May I suggest adding a little "instanceof" magic to match? Like this:
>
> match ($object) {
>
> Someinterface => 'foo',
>
> AnotherInterface => 'bar',
>
> }
>
> this can not clash with any existing code as using identifiers like this
>
> are a syntax error currently.
>
> Currently you could do the same with
>
> match (true) {
>
> $object instanceof Someinterface::class => 'foo',
>
> $object instanceof AnotherInterface::class => 'bar',
>
> }
>
> Indeed, the former could be considered syntactic sugar for the latter. And
>
> I do not think there's any ambiguity here for the casual reader or is it
>
> just me who thinks no other sensible reading is possible?
>
> Thanks for your consideration.
>
> Karoly Negyesi
Hi Karoly,
As mentioned by Bruce, this syntax is already valid, therefor, it can't be used.
what you are looking for is pattern-matching, see "`match()` enhancement" section in the RFC: https://wiki.php.net/rfc/pattern-matching
Regards,
Saif Eddin Gmati.