Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123737 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 B58E71A009C for ; Fri, 21 Jun 2024 16:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718987186; bh=+3sESFLa9W8T21935jrs6CeHoC0IEAZX66SKzBSxT9M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GO/o7dgLWocdctOvpV2mK4ODRNumAx5z33pzU5F7eSzZ0kpPR8E+zqXhN/FkbR6dH 5+2keRMvvcCbptz9l1fQFdsJBwVfvVmyYi8VpCIuY1J225b3dlKpp9BMdP8ESHiPdT EFNZ/e9gn2tVtiuKMOUxeLfyLB6jwdwxEUeRRQVHi2J6s4vtY4DJIjh2Zb345ncagy cU/KdcF9gh4EjLIPOr87Ixtq0nfrpyEPocnUsPhz2YXxaQyIfWwFlqyfekzhgUgWMh OlbZwigemz6Rx540x0iUFfmSJAJ3GnVWNYizkf0cAq6CI16P5Tj+bvE4zCji9ihmSj jeBjx5uXoh1/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 42BE5180B4A for ; Fri, 21 Jun 2024 16:26:25 +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_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-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 16:26:23 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-52cdd03d6aaso56685e87.0 for ; Fri, 21 Jun 2024 09:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718987107; x=1719591907; 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=JLC/rqByFoUQg8IQyRuJ+dbtOxNdFeqvsKsbCIoITYM=; b=lgkqRYA38ICfWgYLPXBF2gyKf5VNBlraeqycBHIWiqA+kJC1pz9rISPR12X8Z2l6Vu 51G27xAzuf8UPRUmfLx/3Cz1X2LzJbBQHedwgR7plmjVa4D5Abs1rlhbBkh6TBpfi4zE TPFYpyqNOTz+JocXOI5NXFKsyGDG18XOaTemE3r+w1gr2OjuLCthm7Z3G6vmMmkfZ71B 6i/IKzIGOLGNMoP6bbSJmEbse7BH4ujC7Nqp+1CcGjTLdF2ka5v9RCVp1wwLUbOqopA5 sdDaWKgv1+vUCFtTnN5QxK44q7hh0JBgY1spILS7ePTtWoTDNOvzTg/V4Dim1UGFKb0j FlQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718987107; x=1719591907; 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=JLC/rqByFoUQg8IQyRuJ+dbtOxNdFeqvsKsbCIoITYM=; b=srcIRUyPpzxWFEUfIlEO8sSWaWxviq7XkXdu3/pNwvERfbLnrjFRytK5oxYFliKPQq ljEf7QJmWFljz9b14Q08HlCV/RqxVToLUydHf++iDocIFAV3gTI6zHU010b8q7vSiEET 7960LQuqmqWiU2OghXYdsoqIj+LBvEYaoroLbEuVH2lB5ltM7l5EkYg2m7VkcG0NiPcX 9xu/jheIsEpW9RcRvsxoamsye7sxBkj7CI5clqBpXhVWcY+tpr54wr4cI2Ccq6aMS2Wo +jxKfxj6UyZ/65WCnSblv9d2o/Kwknmo4lrFFj2I7NJpZbJhMz0Rowl8/JMiMNW3YDfL TM9Q== X-Gm-Message-State: AOJu0Yy5bxErCIKkEK7ARZ9nF1mi/S6Emlph3dctMcJZLbjPG0quU572 qWqcXLWn1C5xiSbKVao/PhI2w1uEgRQl8bInbiImJGiXvQUltTtHkoZeRsU6A0z8PrZDlRe+Yi1 iHauovN63zIzQNx4I1BS6gALaHPpV60XKeF4= X-Google-Smtp-Source: AGHT+IEvyOMvBnWvvUJO9RZEhNFLIJZC0R+9jAvLK7Ya/n/Pu4/tusjPLNqEYkb4XsbDez2wtttYuHABoEc2GJm/ES8= X-Received: by 2002:a05:6512:234a:b0:52c:d21e:32f8 with SMTP id 2adb3069b0e04-52cd21e33c9mr3687350e87.67.1718987106940; Fri, 21 Jun 2024 09:25:06 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <9d28c9tOCChpWUcP1SFiFwtf2-w2XAtDzHsmM73myA7zfBsn7TxxEqs-VCnxRAgZjsk2TxS55owmM8wSLgBQL8LgeQLntUQ9toeLMkjTVx4=@gpb.moe> <673a1803-83c4-44b4-bd73-4ba61e83412e@app.fastmail.com> <350c1531-9bcf-4e7c-824b-8d9904b9e48e@rwec.co.uk> <914cde73-3e53-44a8-94ff-bcf34000cc0c@processus.org> In-Reply-To: Date: Fri, 21 Jun 2024 18:24:55 +0200 Message-ID: Subject: Re: [PHP-DEV] Renaming "strict types" to "scalar type coercion" 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 Fri, Jun 21, 2024 at 4:50=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > Le 21/06/2024 =C3=A0 14:27, Robert Landers a =C3=A9crit : > > This is why I wanted to work on "as" part of the pattern matching. It > isn't clear what will happen with the actual pattern matching RFC > (yet), but being able to do: > > some_function_expecting_int($_GET['foo'] as ?int); > > > > I've started drafting a proposal for strict casts - independent of the pa= ttern matching effort, but might be combinable - but the devil's in the det= ails of exactly when the cast should fail, and what should happen when it d= oes. > > For instance, should cast('abc' as ?int) fail, or default to null? Do we = need different syntax for both? I have some thoughts, but haven't quite set= tled on a full proposal yet. I know we have different opinions about many things, but I'd actually love to help if you'd want it. I think our different opinions might make it better. :) I vaguely remember our last conversation about this and I kinda liked your 'catch' thing. IIRC, it looked something like: 'abc' as ?int otherwise false; or something (pretty sure it wasn't "otherwise") where if it wasn't an int|null, it would fall back to false. If there wasn't a fallback, it was a TypeError or something? One thing nice about "as" is that having typed variables becomes much more simpler to implement (if anyone wanted to implement it) even as a transpilation step: int $x =3D 5; $x +=3D "10"; // type error gets transpiled to: $x =3D 5 as int; $x +=3D "10" as int; Interesting stuff. > > On Fri, 21 Jun 2024, at 13:46, Pierre wrote: > > > And how about: > > some_function_expecting_int(\intval($_GET['foo'])); > > > > intval($foo) and (int)$foo do exactly the same thing; they're basically j= ust different syntax. > > > > And moreover, I'd write something like this, but: > > function validate_int(mixed $value): int { ... > > > > Which is why I included the word *concise*: it shouldn't be necessary for= every user to write or install a custom function for such a common require= ment. > > Regards, > -- > Rowan Tommins > [IMSoP] Robert Landers Software Engineer Utrecht NL