Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123753 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 ADE621A009C for ; Sat, 22 Jun 2024 18:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719081361; bh=DwoECLoGk0RWPTK/a9/teGCQdI2U17ihe7DqNjUzR7o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZKp13ZeN97nCgLZ0Ka9chO/ffZSH+NjE6apK8xdXI9iPJteVZbtLAwsmvdL402oOP i95a+XZd1Xh4VN2bcKTvd11a8J7wTs6TAm80jsZ63mKEvODWnMEdgBWmGYVJDSMeXu iwHn0zgWrW9EnEz+5LGjuUaAq+rfJnuWRbvdJ2IEj3G2kObaxLhz/Cp18Ht9Yr9Kuz 91TbtfAc8/JGDUKfnzYYw7sDVSgC9P12Sf0anyw8YTT28w788WsEduCVY0Ole7/eWa 6y7+aU9Rmr7toRjLzMiIm3ojUqNaAXFdGJGN+NxVZvi+8OhdCzd+pv2qHTQcsaHE5r eAUgEFcvfrsLA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F10D5180069 for ; Sat, 22 Jun 2024 18:36:00 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,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=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 mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 18:36:00 +0000 (UTC) Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2ec59193468so2454521fa.1 for ; Sat, 22 Jun 2024 11:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719081284; x=1719686084; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=th1QEXLrZHr3v2vRLzTJ8+9EUu3hvDwPHxLhBGm/wis=; b=jFtXy8HlopiNS8fE4vm5cTOYNmmv9UbtvNXa6CHxwh+/ju2EkGWesVj72bL6J+3Ads sazkq7Aihv4JBYss1crcnfuml+R1e61kTAv6rnEoXfSjKfzAG0f9BxOf+RVwc/vRVnQ6 QM4FOqAK0JrAmOxYkz9KMPsfhfXz9gQOHkjek/gobEqtAaz1JUzYQWjg+4cLbUOoYtxw edrJlHpDzmnIrVsKBmemeRC30883FPvD19GC6PXHKd99gw8kPuaJweiT8lOc1LrMj/+F m4BFnh4yN72Wi5qBOExJZ08hh6Nce7T8abYjgMWLKo3OWkWM/bkV/DF9nM1DbAblb2/p qGiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719081284; x=1719686084; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=th1QEXLrZHr3v2vRLzTJ8+9EUu3hvDwPHxLhBGm/wis=; b=Mj0HAKcQw8lVFBl99TfHTR1LrlrilUuOGDaalt9DFsbq9PTGaUGzJU2WOxE8wkgSW8 cxP07NzX7IuAv2OMSveW7TVqZwAUBed+y9asz1SHFPLyHQg87HjD+w280Ge9rV6c5SFh et4JDr3SflsnEYAua/NNnz/UKqy48yEuaCGJyhk8yf1A9UyhdwPTl7ijlwoujYgXXQ1O Cvi37RTyVTzetc/j+GnW85QBLs66vX+lxkiWb9Sj8JyLZWEM/Ah+/40RTR4sAH5KKAN9 3xbwWrYjF+xiqvEtKAK0syiAsLVwD1odSaDo46tpnL+hK/9Mx1g8H3R+I2AJBBqSewNu t15w== X-Gm-Message-State: AOJu0Yw59BNqq0KANiP/TAf/WoQ+tiGEbRjxJnIEkoBDZKa05JZ7upCZ tFDgiHLiHlfyEqbTjgnqJXySyDo5ELi/ZkGReCX0Gknp6KIRus6jGnQ0qj0+oZJCatRTncyPeaf Jq7lpJiZFUaNSQAZqFOunsfhhEY5/mjob X-Google-Smtp-Source: AGHT+IFRVSnrtdCjSuhM4OmuwwHmLGTKAfg1bpbqkyw0gPxh4erZB6KxY+0r5InaQ9p3O+4qaB49O6l9EMvFh8NG5YE= X-Received: by 2002:a2e:320f:0:b0:2ec:5006:a9a with SMTP id 38308e7fff4ca-2ec56bc651cmr5279791fa.19.1719081283455; Sat, 22 Jun 2024 11:34:43 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <978b7177-8a22-41c0-94ce-d5539a2468c5@app.fastmail.com> In-Reply-To: Date: Sat, 22 Jun 2024 20:34:31 +0200 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Sat, Jun 22, 2024 at 8:04=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 21/06/2024 19:29, Larry Garfield wrote: > > Valid points. The line between validation and casting is a bit squishy, > as some casts can be forced (eg, string to int gives 0 sometimes), and > others just cannot (casting to an object). So would $a as > array<~int> be casting, validating, or both? > > > I think my concern is that both "x is T" and "x as T" read naturally as *= expressions*, where their main purpose is to evaluate to a result, and side= -effects are exceptional. > > From that point of view, we can give intuitive meaning to the following: > > - $foo is int =3D> boolean; is $foo of type int? > - $foo is ~int =3D> boolean; can $foo be "safely" cast to int? > - $foo as ~int =3D> int; cast $foo to int (unless unsafe) > > But then what does this mean? > > - $foo as int =3D> int; cast $foo to int if it's already an int !? 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." [snip] Now ... that being said, I'm def not a fan of this "~" thing. It makes no sense to me. Semantically, what is the difference between "123", 123, and 123.0 other than how the bits are arranged in memory? If it can become an int -- regardless of how it is laid out in memory -- I expect to end up with an int as long as it is an integer. I would find it super annoying to have to fix that bug report with a single character, just because someone returned 123.0 instead of 123 because they rounded the number and I got the result from a callback. Further ~ means bitwise-not, so when you start mixing in literals ... what does it mean? $y =3D $x as ~1|~float; What is the value of $y? Is it the literal negative two, casted to the literal one (int), or casted a float?