Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117442 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69087 invoked from network); 29 Mar 2022 09:31:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Mar 2022 09:31:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E1AB31804C3 for ; Tue, 29 Mar 2022 03:59:13 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 29 Mar 2022 03:59:13 -0700 (PDT) Received: by mail-pl1-f175.google.com with SMTP id c23so17312643plo.0 for ; Tue, 29 Mar 2022 03:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ClssVTGnB2UqUqDut4Ft3JAz+B5KgvJOeK8eDieGYuc=; b=csHuaG0IYAa+USZCJbM1WUxQyHmlQJAeC/91NqFTR4FST5ue4rPwUjw99F9Iq/ZYDv IIsr/aYi1Osjx1rh3eoh3C1vYrG26KBgU6Dr83VR62gB7Knm+mGLe9h2NUsAM/nPbIF+ v3ZDKMWgtuHXglnBxnkR7f78EED4tVktpfVqLenPIsxyk9Zw6ApxIe5PqoZpzJT+rI1a Qnw/7v6JoT0+duK6Lf3EI2FPoXe76PLmWBOLOUDOXpnCht8Xb43lRZYzt1vEH0JaSd9u 7Qo7tODHr60DM/azZodVCi3hPigUhacJ3HN9Dh23FevSN1FIff4Ai9XMR1eyeqNDmJ4s OZ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ClssVTGnB2UqUqDut4Ft3JAz+B5KgvJOeK8eDieGYuc=; b=oT/Oq9wmgppcoz3Qn4hwdhrZAWqzdEoY7TCkPxui75iEi+VUi9uuUOLp6P6BEqQ0l1 B5r7kHoC2S0DIA5UjD1RE9JpTg/X0DtLhFtsTAlpSOW7b3vh8znTIn4JpQXn9DSLf6h/ qaP32CSKxzFGMdrffdcnEgg911C2OZvorAu2MyLc+UApsz+7nJkTJwmQV3DTNeky66pf LAIgqWb2lGM+bRWQZLsfkTxfOrISnzdPxWdKDiefvja3sxZ187IaQ8QnNoY3GDWLzTFe T75WFhxzM+BdZxLHpOzBaEviIk20LG2inrUtNGZJ4+z36Lkk98zJT2Ex9wdd5olgg0Ty WyvQ== X-Gm-Message-State: AOAM531VNtIx/LmlmGr14V2/n89RK0H/4CkXZFR4yzJzSX231UDhXUL0 oDRTRstz0vdnvCvFRzXO16cot+wYy8mw7xXlSqU= X-Google-Smtp-Source: ABdhPJysddeSxMBYKMmfr4dq/5kG4iRupH7R3ozMSZs45SSTDB0JNH9Vv3MsCuktmMIa5j1OgOwYEYSdDxwvN8Z5wCk= X-Received: by 2002:a17:902:7896:b0:153:9f39:ae97 with SMTP id q22-20020a170902789600b001539f39ae97mr29385158pll.13.1648551552531; Tue, 29 Mar 2022 03:59:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 29 Mar 2022 12:59:01 +0200 Message-ID: To: Bruce Weirdan Cc: "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] instance version of match ? From: landers.robert@gmail.com (Robert Landers) On Tue, Mar 29, 2022 at 3:47 AM Bruce Weirdan wrote: > > On Mon, Mar 28, 2022 at 7:56 PM Karoly Negyesi 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.