Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123762 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 98D0D1A009C for ; Sun, 23 Jun 2024 12:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719145062; bh=dYIrBaalmjCzRDNC88sXJmZWmYp3pPIdV31s4wTEYwY=; h=Date:From:To:Subject:In-Reply-To:References:From; b=EDzv92Rm63WNTcmLIUlZv+W7hI3XbBemEGiMcr4dl+FvB+12JskX4TfkPIfoO+Wed 6bBbOo/OrFvmYH4JgD6NCbIsQGhPvNBkasZ8oPEAaE+u04JrKCykWox5CNz4g4IhF7 0obzfYffRc5F9ZgPOXOdBH80D3+AFmy6dWkndwx3XmQHUBeYks69lRTYaBmLXDpfhK LvVZwhJ1+rEGqQXAZvrz0zQMJPSBlbriWuvqsx4lOtO7gbJHmZi32Bhs51GI/Nwhlv n9OFN8efdVZAQJkWlI2K/YDDPycrvQaJWI+4DaY+/BGaL8GIsnOQz+v6gilw6sLE4c d73+vC5N2ltcA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DFE7018005B for ; Sun, 23 Jun 2024 12:17:41 +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,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 fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 ; Sun, 23 Jun 2024 12:17:41 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 3AB4C13800D7 for ; Sun, 23 Jun 2024 08:16:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sun, 23 Jun 2024 08:16:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding: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=1719144985; x=1719231385; bh=T1FXIC/1X06wEfsbTlXZbUxOwFuuV+swrvxkm7SBT60=; b= EgdcJ1xTmvLWiYLiwmVGjfZstsGcoC2d1KPfcRFHdGnwgsit8HNFG1mUtj+Sz997 XiHfScCGqFK/N7m6Na+lycX7lNeNJ3VZFn1AAatDDLVUUUc1+sFOeQitrwnXG37+ gRXhe7I5DsPg8AJAxX4p4HXSH0cRqqZfyevmYozNlCz4b4eb1bT0uiWN0DnuPvhC AKlWaNN3v36d0kMav2ZXYAxw+wz6Gy0ubiMN26s5HqnuYKg2u6MtFaeffLjhLuim 8Yx7yXovpRkhPZSuKVk+3D6GncYj76Igez75XPTInW+YhuxpfjpNEIt+lk93odd3 gYf3DZPdIzs3lP5aq1+/tQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1719144985; x= 1719231385; bh=T1FXIC/1X06wEfsbTlXZbUxOwFuuV+swrvxkm7SBT60=; b=U 2mr6/YWvM/WRSiFzShc4jF+1e7s56vNKz1xZJ899mPUROIbZyOIHi8wyiJZnbW6M IEM7k42h8MIGpZtzuM1Sydb6wnrKwmiErcvirFM+OQBFOeLdtZ9Vbk2Lq/pDU3LO iI87pvnBMETvQhmFed4xQdA3xkyMT8mfmd0goJ+s9PnoKXSWovWyTiqqXk0qU74M MoZ0WQgqyJ0KtSgA2CbNY1L09sJz43APXAy8sSusz4jLJtQWcfrAo3aqqUTa9eh6 pcr6cEAFgXjZIIPrHXOotm9nilqkJYw5XjeZVfFempQ5lHcQt2/FLKQ2F7Hlp7Ai QgeLXLpd8+nd45DFZq/5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeefledghedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvufgfjghfkfggtgfgsehtqh hmtddtreejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdf uceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpe ehleffteeigfevudetfedugedtudevledugeeugeelheeihfehgfdtkeevvefgleenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprd hphhhpsehrfigvtgdrtghordhukh X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 23 Jun 2024 08:16:24 -0400 (EDT) Date: Sun, 23 Jun 2024 13:16:21 +0100 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching User-Agent: K-9 Mail for Android In-Reply-To: References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <978b7177-8a22-41c0-94ce-d5539a2468c5@app.fastmail.com> Message-ID: <642D9E7C-0328-4F30-8B09-3DB4AF42914C@rwec.co.uk> Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 22 June 2024 22:57:24 BST, Robert Landers wrote: >In general, you assign the result of the operation so that the output >is useful=2E Here's how that might look in PHP with the C# rules: > >function foo(BarInterface $bar) { > $baz =3D $bar as Baz; > $baz?->thing(); > $bar->otherThing(); >} The difference is that in C#, there is an actual difference between the me= thods available on $bar and $baz=2E The "as" is performing a conversion, so= the English word makes sense=2E In PHP, all we could do is have a one-off runtime check, then return the v= alue unchanged=2E So written out in full, that would be: function foo(BarInterface $bar) { $baz =3D null; if ( $bar is Baz ) $baz =3D $bar; $baz?->thing(); $bar->otherThing(); } Or: function foo(BarInterface $bar) { $baz =3D $bar;=20 if ( ! $bar is Baz ) $baz =3D null; $baz?->thing(); $bar->otherThing(); } I can see some use in a shorthand for that, but it doesn't have much in co= mmon with casts, or any meaning of "as" that I can think of, so I don't thi= nk that would be the right name for it=2E >With fibers/async, "as" is actually more important than "is" (at least >as far as crashing goes): > >class Foo { > public BarInterface $bar; > > public function doStuff() { > $baz =3D $this->bar as Baz; > // some stuff with $baz > callComplexThing(); // suspends current fiber, > // $this->bar is no longer the same object > // or concrete type when we return > $baz->something(); > } >} The thing that's stopping this crashing is not the "as", it's that you're = backing up the old value of $this->bar into a local variable=2E Nothing abo= ut $baz will "remember" that you made some type or pattern check against it= just before/after you assigned it=2E >However, it becomes far more useful to dealing with >scalar casts: > >function foo(int $type) {} > >foo(123=2E456 as int); // crashes >foo(null as int); // crashes Yes, those are actually casts/conversions in PHP, and I've repeatedly said= I'd like to have those, on top of the "never fail" casts we have now=2E Wh= ether that's with an "as" operator, a "cast" function, or some extension of= the existing cast syntax, is an open question=2E=20 Crucially, though, I don't think most *patterns* would be relevant in that= context, as I pointed out in a previous message=2E Regards, Rowan Tommins [IMSoP]