Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123725 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 EBF551A009E for ; Fri, 21 Jun 2024 12:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718973614; bh=9wf81aE9MRSu8N8MCDuGDBuklF0+N67ALpsPaQcoMqA=; h=In-Reply-To:References:Date:From:To:Subject:From; b=fjBWf8BVdHB8fjay6crPkKrytpT3oLRZ4Z36XDC/7ynSC3Rf16y7iWom6Y89NV9+s d8zwajOIKxzWUh2T23UYk/rlgpv6VrtwUGi2za2lKpjcqNs/+NFWUjtxwV4cufFERy UK2S3wjz+gEywaRhq4YVW/GHUQsj6qxyEgcCZLl8D9cBGOU1LNA9fYKPIgkzbNxSbO yK6Cj4GAXgJNXwDxSgRiITwKpdrNixHOa0U5v/J9oqfETCRR1J20N0DWLITSUKWFCP DZOh9dPTMiPHRTwCLfsL7PRVfhv1BFpnVB1bLPOYKhUkg7PMOXzOvI9xYJEbL13OA8 qWFQW6bVFvzlw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CEEE0180386 for ; Fri, 21 Jun 2024 12:40:12 +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 fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 ; Fri, 21 Jun 2024 12:40:12 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 5EFC213801CB for ; Fri, 21 Jun 2024 08:38:57 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute6.internal (MEProxy); Fri, 21 Jun 2024 08:38:57 -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=1718973537; x=1719059937; bh=NR2SbEwofQ VaQi2dZVqR3mYxXMTjk8SxJkUiEX4Nqzw=; b=DxBehLjL/lly7cweaC6dkHJFNX RMq/0gPKU8Ei5HvNE0os07EVc3tj/i9HuTECQvBTdlGymlH3kJKntG4lSe0fkmPz ry90Cm2rYh4MpVZxlc3YfKzRDttXadLbJERz70HVHOQLx5grWHtbEmYA+qYlLWte lop09DMDNFjiUfEIGeWPJVC1m4boA0+67Jgv9F3sEZqoUCcWSCDtffj28wnugtJA dgDxBZSa3EwkbkXTO0JOMouEILVoDCc65JfAXsOBF6vt5n/j03IK92f/+iguhAAR 1OvFnhRIlQxPGBNTEQbi7ZKJVb3HrkJcB+fduqYUqPWaEEeoWPjZZ+aqs8gA== 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=1718973537; x=1719059937; bh=NR2SbEwofQVaQi2dZVqR3mYxXMTj k8SxJkUiEX4Nqzw=; b=BuEcLwYlE7npF1wiHvcMXZTM/d+kDDIZReN4MOf4u65u rBnbDkmo/RuKBXpm+4B7OiIOTQSb9uOoVhUMDSf8WSkPymlt79qn7EhOD5/I8ch1 oEvKftciXwv4AmQVCpa1VvOs16Wt2L/IlUBDqPgOn6Uder1cHxiCwnN9UuMgjZCQ J0nANIvZ6pPR3UcVdr5/epI9NTC+MgjqbmAy+p093LqwPof9m/alP/aFEAEVV6h8 FdhXWVEsZkQQ7yOb4dEjXMV+L1qoKh89sO95ETRSQUxFWLB6LNzPgPK1qByYv494 xOEHeT7Ipaug8gLcCMA5i66AdFV5KIOe4Q7vmU6ypQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeefgedgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsehttd ertderredtnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdf uceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpe dtudeiieffleevtdduteeuffegteevteduueefgfekvdekffeitdfgveeuveehueenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprd hphhhpsehrfigvtgdrtghordhukh X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id DA2F71700093; Fri, 21 Jun 2024 08:38:56 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-522-ga39cca1d5-fm-20240610.002-ga39cca1d Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <978b7177-8a22-41c0-94ce-d5539a2468c5@app.fastmail.com> In-Reply-To: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> Date: Fri, 21 Jun 2024 13:38:36 +0100 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching Content-Type: text/plain From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On Thu, 20 Jun 2024, at 18:38, Larry Garfield wrote: > Hello, peoples. > > Ilija and I have been working on and off on an RFC for pattern matching > since the early work on Enumerations. A number of people have noticed > and said they're looking forward to it. Hi Larry, I haven't time to read through the full RFC at the moment, but a couple of thoughts: As Andreas says, we should be careful not to pre-empt things that might be added to the type system in general, and end up with incompatible syntax or semantics. That particularly applies to the generic-like array syntax, which is quite likely to end up in the language in some form. The "weak-mode flag" seems useful at first glance, but unfortunately PHP has multiple sets of coercion rules, and some are ... not great. It's also not immediately obvious which contexts should actually perform coercion, and which should just assert that it's *possible* (e.g. match($foo) is { ~int => (int)$foo } feels redundant). So I think that would need its own RFC to avoid being stuck with something sub-optimal. Similarly, the "as" keyword has potential, but I'm not sure about the naming, and whether it should be more than one feature. Asserting a type, casting between types, and de-structuring a type are all different use cases: $input = '123'; $id = $input as int; // looks like a cast, but actually an assertion which will fail? $handler as SpecialHandler; // looks like an unused expression, but actually an assertion? $position as [$x, $y]; // looks like its writing to $position, but actually the same as [$x, $y] = $position? It's worth noting that in languages which statically track the type of a variable, "$foo = $bar as SomeInterface" is actually a type of object cast; but in PHP, it's the value that tracks the type, and interfaces are "duck-typed", so it would be equivalent to "assert($bar is SomeInterface); $foo = $bar;" which isn't quite the same thing. Regards, -- Rowan Tommins [IMSoP]