Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123756 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 9F90F1A009C for ; Sat, 22 Jun 2024 19:26:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719084479; bh=Q8Nq62eTkppqBqirFbt6IGF0BhFLi2dDB55TOubqy6c=; h=Date:Subject:To:References:From:In-Reply-To:From; b=hNh9vuhjLaPmy5bw1ASEU2Cmj+LH6Tf3dtQrqlIqkgCjfKzrPz3qadrK6betp1cfF Fupa/Wdb+UDxHh2jgtmUHuja9x/m2mHDpdbe2MIstBF26lnvgOf8/F617X2y0IPgHl +kH/+PXm+L1Yu1fwnxf94fXoFBAsklqsyW3mL8J2iMqgTiFwNgVkQjoPTTqiKpuYXQ vkwzMvM2zRQeD+J4uBZbZARbZkJRAvmKV3fA5oE0uzQiT7o7fWsOPixV5LTDiKSfpM I2jNSnqYu7Gy+P2wlucoeQutJO5Z7VICAwLK7hm95VUgI8HfebrL20BbSRMlFe/1Xe zbzIbXeK3ttAg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 68699180A57 for ; Sat, 22 Jun 2024 19:27:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 22 Jun 2024 19:27:57 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 0281613800A6 for ; Sat, 22 Jun 2024 15:26:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sat, 22 Jun 2024 15:26:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1719084401; x=1719170801; bh=Lhl20QKJ2W yPyfiHk5rCcYSbcZ6d7my4yD7EiOS1jD0=; b=UmX2jd1gTuJlxFcgI2rxJJOAoh VvChOmht2S27AsMVkVdlFhXg3Cu0JwQvkafCVg027zb85+i9/8tOHI7WQKzSiz4K DIsf63BWeAcE4UqCkUwD1oR2MGNHBWmuMehbpxQ4n4Q4JRy99fZxiIvdX/Qxv8ic JZXsiGxLLVNRNBXRkMlklsMP/+RIi1QAOB6t6ERWLwz9kEEuYi4LAH7r0ujnkhGQ PF0sIUWdkx386tGdaWrsVe0d2/J3/nVAHaaWTmCehA4pyps6bGdRjsKQ0jlLbf44 KSauzlzUF7WMYPyiCJ9Oj/r9T/uD5pI9UksIFTivw5RfJCNtXh72TsyvJNhA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719084401; x=1719170801; bh=Lhl20QKJ2WyPyfiHk5rCcYSbcZ6d 7my4yD7EiOS1jD0=; b=TlkbIcydX0oYMO8rDUHY/Us67t01uZ2k6jzB8B/HVUcG qnm1BV84LfyrFihxI223Hdi45HcukNXIpj+29os0WavhLOwPbo9hjFc4abYsxCCG umQ1u+ngoimS8Ela/ubNzxiD3e+1EhoZOy+KfBeB7QAGhR+6CPxpvbHjbIl66xXv +h0Y7VhKDfQt41u2ZG/mwCCf9zrHqo65VlxvD4R7uUDui989TmpAnIdf3S4vTsCU 24IeUvG39CCVA76yNPZmoP2hinj2nFNRqwQOoUxqB6NXCNF5yGdLBUmtDPhdjAWA e9SZy6rjUHx3vLJYNAw/DIC30Hw51hlCxUaf+SA4aQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeefiedgudegtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtd erredtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdf uceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpe evleeuheetffelvdfgudegledvhefhueejgeeileeuhefhledvffegffeuuddtheenucff ohhmrghinhepmhhitghrohhsohhfthdrtghomhenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhu kh X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 22 Jun 2024 15:26:41 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------8SzbuzkldCh2DBH27VC70ec2" Message-ID: Date: Sat, 22 Jun 2024 20:26:39 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: internals@lists.php.net References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <978b7177-8a22-41c0-94ce-d5539a2468c5@app.fastmail.com> Content-Language: en-GB In-Reply-To: From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------8SzbuzkldCh2DBH27VC70ec2 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 22/06/2024 19:34, Robert Landers wrote: > I've brought this up before, but I mostly see "as" being useful for > static analysis. That's what I've mostly used it for C#, anyway. > Logically, you know the type, but due to one-thing-or-another you > can't "prove" the type is that type (such as foreach-arrays or dealing > with results from user-code callbacks in library code). I want to be > able to say "this is an int or else." I absolutely see the use case for that; I just don't think "as" is a good word for it, because that's not what it means in normal English. Incidentally, according to the C# docs at https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#as-operator > The as operator explicitly converts the result of an expression to a given reference or nullable value type. If the conversion isn't possible, the as operator returns null. Unlike a cast expression, the as operator never throws an exception. So it more closely matches my intuition: a statement of just "foo as Bar;" would be useless, because it's calculating a value and discarding it, with no side effects. As you say, the conversion might not be of the value, but of the statically analysed type, but in C#, that's all part of the language. In PHP "$foo = $bar as SomeInterface;" would have no visible effect except in third-party tooling, where it can already be written "/** @var SomeInterface $foo */ $foo = $bar;" -- Rowan Tommins [IMSoP] --------------8SzbuzkldCh2DBH27VC70ec2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On 22/06/2024 19:34, Robert Landers wrote:
I've brought this up before, but I mostly see "as" being useful for
static analysis. That's what I've mostly used it for C#, anyway.
Logically, you know the type, but due to one-thing-or-another you
can't "prove" the type is that type (such as foreach-arrays or dealing
with results from user-code callbacks in library code). I want to be
able to say "this is an int or else."


I absolutely see the use case for that; I just don't think "as" is a good word for it, because that's not what it means in normal English.


Incidentally, according to the C# docs at https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#as-operator

> The as operator explicitly converts the result of an expression to a given reference or nullable value type. If the conversion isn't possible, the as operator returns null. Unlike a cast expression, the as operator never throws an exception.

So it more closely matches my intuition: a statement of just "foo as Bar;" would be useless, because it's calculating a value and discarding it, with no side effects.

As you say, the conversion might not be of the value, but of the statically analysed type, but in C#, that's all part of the language. In PHP "$foo = $bar as SomeInterface;" would have no visible effect except in third-party tooling, where it can already be written "/** @var SomeInterface $foo */ $foo = $bar;"


-- 
Rowan Tommins
[IMSoP]
--------------8SzbuzkldCh2DBH27VC70ec2--