Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117443 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77558 invoked from network); 29 Mar 2022 11:05:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Mar 2022 11:05:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C368C1804DB for ; Tue, 29 Mar 2022 05:34:04 -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=0.8 required=5.0 tests=BAYES_05,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, NICE_REPLY_A,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-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 05:34:04 -0700 (PDT) Received: by mail-wr1-f45.google.com with SMTP id h23so24579408wrb.8 for ; Tue, 29 Mar 2022 05:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=ztcOFrmejchGJ28+/MpzYeUUX7panr5Lw2Yp5A2A9mI=; b=eK3tCVCkkrWK4BIetDFFHjnj9q1T3DyT2IXDKx5C/oo6BkoTYqiAJgYA+ln0Yfdbxt X2sFXmpMLQ3jh11fU6SGSVc94B3Mgyiqku+EOVEoKkcx0kuk3t4sijPRS6EqnWIRm5Jg x3Uqsq0dsa2DVUlTt8S2LgUTbfDSshvKYxk9fR84Kcxa2/wMzVQw6V+axQFm5wBXHIT8 bCw9VtBHX4BJncF+qH0lgQa/mdGmCrApN8TFKTGCyq8m307IKON69G88Y+m5dMRcGVDg 0IPf7AYBA4k7NZLE5h3PLlQ99VPTCUQuCnKUmra1hNlCeSDOjNco1VGQc0C5E06a7i1H mYbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ztcOFrmejchGJ28+/MpzYeUUX7panr5Lw2Yp5A2A9mI=; b=Vj2QQzn5lm40Ti6ZpL8jv3FNNRtM4h0pC7JrJ+682tIcX4VAIdfyPNatIYQeBfglXU hrw9OxATCKK0diLL+zEEYuNJSpgVBW86COqKZDTH3z8tEqT+/a3wpiiMOZrgmWEYVeP2 YjK5c3J8NEK26Wv8Fn8NJuqNPlBVT7MMcotQXY6iD1BKladEVC48qOovvT+XQ3BhsXos BP8ucE347zsPjMvK/n7KkOPj/sQfvPUcaEUecLY9B3vu/9bFKbpZo6ShkdpUuH0AWiYH +HiLxCmzOSMwpx5VJRlZRVbpn6SHkXs+9Ox98KUsR6rvqZ2VIzwZAHmb4LrEmvaas/D/ yESQ== X-Gm-Message-State: AOAM530XXgB0JgglRVkN135aeD9xOLdFgoZwYv2hlbFATZFxFsdd92ma vyF2kCCu6rnhxTlWH2qm2Eawviqr+DM= X-Google-Smtp-Source: ABdhPJx82VB7qesRnP07Yvylt8Vc7PzVn1sUFf4yh4P5bfhcWpxJ74+G1235PWCyY6CVDQEuEVuU+w== X-Received: by 2002:adf:82b2:0:b0:203:f34d:dff with SMTP id 47-20020adf82b2000000b00203f34d0dffmr30422129wrc.661.1648557243135; Tue, 29 Mar 2022 05:34:03 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id x13-20020adfec0d000000b00203ff46f802sm21116156wrn.36.2022.03.29.05.34.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Mar 2022 05:34:02 -0700 (PDT) Message-ID: Date: Tue, 29 Mar 2022 13:34:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-GB To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] instance version of match ? From: rowan.collins@gmail.com (Rowan Tommins) On 29/03/2022 11:59, Robert Landers wrote: > $object instanceof AnotherInterface => 'bar', > > We can see that `SomeInterface` will resolve the interface and not the > constant. Yeah, the instanceof operator is magic in that regard - it has a special parsing rule to consume the next token and avoid it being evaluated as a 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. That wouldn't work, because the type of value passed to match() can vary at run-time, but you'd need to compile the expression one way or the other. If it did work, it would be extremely confusing: function example(string|object $input) {     return match($input)  {           SomeClass => 'found class',          SOME_CONSTANT => 'found constant',     }; } var_dump( example(new SomeClass) ); var_dump( example(SOME_CONSTANT) ); Do both of those matches succeed? What if I set `const SomeClass = 'hello';`? So unfortunately we need some extra syntax to say that something should be an instanceof check, and therefore a class name. Regards, -- Rowan Tommins [IMSoP]