On Tue, Mar 29, 2022 at 3:47 AM Bruce Weirdan <weir...@gmail.com> wrote:
>
> On Mon, Mar 28, 2022 at 7:56 PM Karoly Negyesi <kar...@negyesi.net> wrote:
> > match ($object) {
> >   Someinterface => 'foo',
> >   AnotherInterface => 'bar',
> > }
> >
> > this can not clash with any existing code as using identifiers like this
> > are a syntax error currently.
>
> That's valid code actually, see https://3v4l.org/BEcE4
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>

It can be modified to produce ambiguous code however:

const SomeInterface = 1;
const AnotherInterface = 2;

interface SomeInterface {}
interface OtherInterface {}
$object = new class implements SomeInterface {};

var_dump(
    match (true) {
        $object instanceof SomeInterface => 'foo',
        $object instanceof AnotherInterface => 'bar',
    }
);

We can see that `SomeInterface` will resolve the interface and not the
constant.

I think what they are proposing is that when the match is an object,
and the branches are class/interface/etc names, it should just do an
`instanceof` operation instead of a value-equals operation.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to