Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123720 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 7555D1A009C for ; Fri, 21 Jun 2024 09:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718961246; bh=Pj7PZWG3qEJbSQbIjVzzw0dIXQMShUXH6SOsv5ZlSRs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=H6d16jwVodvlaWaq3a4iBG3vinx12eAmVFha60LhfU8Pbfvp4dUXf9yIPKOTBn8UI Nvc40qCW4tSmrSXPUEZUBZo6Si8e6awYKLMXeQybiuikBvp6wUXdLsCSvq+Z0wnDG+ 7CPr6SQd3/FKM6RREni/lSIxe/UDekMfoGToTH8g1xtZg8pExSZh87mFm6yYC82N4w 7RxxRSVE6hHo9KDHpfmU+rBHhH2yyouRva4fKyD0sgjMmhNQ2PBpgkbRb696dNUI6D yD+3UKhJik/R/TLgYvaS7XwFrloxGS2oo6R9kRpdOgeylCuqQ/pOumUiToM0PKrnXr 1+hnEqEcsxE7Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C1161806A4 for ; Fri, 21 Jun 2024 09:14:05 +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, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 09:14:01 +0000 (UTC) Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a6efe62f583so173953366b.3 for ; Fri, 21 Jun 2024 02:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718961166; x=1719565966; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6GnOncysybOY8RKTPeTF2wWZUmqM6Oov7tHw/tSUD0s=; b=PV41/PmAlpMJSMaQ697k+acl10F+K7k/A0kBAcKzKzQoU4IZtQArmB0I9t5uXXo1Vd dKzumfy+D6IvZ+D/0VLqLbaeSLy8j6vEVN1qw07tH+mHdc69SzhiORjxNsMOS7malV8I u34YKTQttZ5Bzh6TnRgGKdzKBY3VDJguhPd9mmXSB7BN6mzqkixDm2lJiuMar3sZbZgQ mDPSlfLi3yVOLyHw0NK6MzrURK7fSa8thQgDqKeTpaUyMqT9eLoG0Yq0WVKWnegrND0A Ee+BlL/snCpAaFzQmX7upSlGrvjDBQ8FzQiymAXwvJB5/0ZbIxo0ZUz8jwszqquu+qCm NHEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718961166; x=1719565966; h=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=6GnOncysybOY8RKTPeTF2wWZUmqM6Oov7tHw/tSUD0s=; b=W5c3z6jYOa/yjjrh3ayqml9KpjIYUID2xr8oSsfaJIB5VnAr2wJeLIclsKOb15eVnX I9ebMrA0BTGdin2ER2ojhjAirFzOsHAc4OkBSSgQ/PTMR5XlPZ3FzYFpwDA0grzArVu3 E2veo85SJa5X90NbpkW1ZEO5qHPuqwlPJHK+vwp1FhkZ2xeQ0QUPmmcaDGXOoAVX0tZM EF6onS7byl4rYD5kxuQIdwX37YexqHDLeALje+ANHhhG53KUIJyNqPEgsH2Hxv3gKbK8 WnByviQH36wGovRs6X+P44XpTcrc4IR2Wg+GE7A8gPHKCNK9lnPDjL+aTl/K0nEBKzrK T7pg== X-Gm-Message-State: AOJu0YyU5o5WUk6wSr7umgt1UT1Fd+xowW/I5+uktgZmnjEdVr+phre4 Mma34zPn60OoY6HJXaesqnTBuxSNztdj/XXN8/70Cwht5iUJ/wPQEg+yLLJ+x6aDyX4J3YVkylu Inv88tEFQUX+aftlAujfN6u4XuYF2pAcaveI= X-Google-Smtp-Source: AGHT+IHgNLJdjEQUASJcFRdMky89vs5FmL/nnG4WahYdU6EmX5dEleHg/TFl3dBXtVqQKNcC5L7p/vBeSt0o3yt5rUI= X-Received: by 2002:a17:907:a607:b0:a6f:91a8:e47c with SMTP id a640c23a62f3a-a6fab6072f8mr621764166b.7.1718961166072; Fri, 21 Jun 2024 02:12:46 -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> In-Reply-To: <350c1531-9bcf-4e7c-824b-8d9904b9e48e@rwec.co.uk> Date: Fri, 21 Jun 2024 10:12:34 +0100 Message-ID: Subject: Re: [PHP-DEV] Renaming "strict types" to "scalar type coercion" To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000afc31d061b62d591" From: dragoonis@gmail.com (Paul Dragoonis) --000000000000afc31d061b62d591 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 20, 2024 at 11:54=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > On 19/06/2024 16:34, Larry Garfield wrote: > > Also, as someone who does put every file into strict mode as a matter of > course, and appreciates the many languages that do not even have a > concept of non-strict mode (like Go or Rust), I really don't appreciate > the backhanded comments in this thread about people who, you know, care > about type safety. (Something that weak mode, when it was introduced in > PHP 7, only marginally provided if at all.) Strict mode prevents bugs, > full stop, and we should not fault anyone for applying that bug-stopper > tool liberally. > > > Hey Rowan, What Gina, Larry and Sebastian said. My $0.02 is 1. typing "declare(strict_types=3D1);" is already cumbersome enough, we don= 't need to be adding more words and complexity to it 2. adding the word "coerce" or "coercion" to a thing is really not good from a DX (developer experience) perspective. It will not add clarity it will add *confusion*... "What is this coersion thing I've never heard of" 3. remember who the target audience is.. Rust and Golang are not beginner-friendly or entry-level languages, so the fact you're even using Rust means you know what you're doing and likely know what coersion is 3.1 PHP's strength is that it's beginner friendly and by that I mean just remember a significant portion of our userbase are Wordpress developers (and Drupal / Magento alike) .. and many WP devs won't have even heard of Dependency Injection before nevermind the complexities of type coersion, so we need to keep things *simple as possible* at all times 4. I think the solution you're looking here for is better *education* to the end-users, on what the implications of X or Y are .. rather than changing the language itself .. so the merits of your proposal are good, in that it helps the end-user understand the system better .. it's just the solution you're proposing here just isn't it (so far). Used correctly, it absolutely does. Used incorrectly, it can actually end > up *hiding* errors. > > I've seen lots of cases where code like this: > > some_function_expecting_int($_GET['foo']); > > Gets changed to this: > > declare(strict_types=3D1); > some_function_expecting_int( (int)$_GET['foo'] ); > > Even in PHP 7.0, the first version is actually *stricter* than the second= , > because explicit casts never fail, but parameter coercion (mode 0) always > failed for strings like "hello"; as of 8.0, it also fails for strings lik= e > "123foo" and "". > > And this is exactly the kind of code that coercive type hints were > intended for - HTTP is a text-based protocol, so most PHP applications ar= e > dealing with string input and output *all the time*. > > One of the things the language badly needs, and I have been trying to com= e > up with a proposal for, is strict type casts, so that this code can > actually be written safely but still concisely. > > > Regards, > > -- > Rowan Tommins > [IMSoP] > > --000000000000afc31d061b62d591 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Jun 20, 2024 at 11:54=E2=80= =AFPM Rowan Tommins [IMSoP] <ims= op.php@rwec.co.uk> wrote:
=20 =20 =20
On 19/06/2024 16:34, Larry Garfield wrote:
Also, as someone who does put every file into strict mode as a m=
atter of
 course, and appreciates the many languages that do not even have a=20
concept of non-strict mode (like Go or Rust), I really don't appreciate=
=20
the backhanded comments in this thread about people who, you know, care=20
about type safety.  (Something that weak mode, when it was introduced in
 PHP 7, only marginally provided if at all.)  Strict mode prevents bugs,
 full stop, and we should not fault anyone for applying that bug-stopper
 tool liberally.



Hey Rowan,
=
What Gina, Larry and Sebastian said.

My $0.02 is

1. typing=C2=A0"declare(strict_= types=3D1);" is already cumbersome enough, we don't need to be add= ing more words and complexity to it

2. adding the word &q= uot;coerce" or "coercion" to a thing is really not good from= a DX (developer experience) perspective. It will not add clarity it will a= dd *confusion*... "What is this coersion thing I've never heard of= "

3. remember who the target audience is.. Ru= st and Golang are not beginner-friendly or entry-level languages, so the fa= ct you're even using Rust means you know what you're doing and like= ly know what coersion=C2=A0is

3.1 PHP's streng= th is that it's beginner friendly and by that I mean just remember a si= gnificant portion of our userbase=C2=A0are Wordpress developers (and Drupal= / Magento alike) .. and many WP devs won't have even heard of Dependen= cy Injection before nevermind the complexities of type coersion, so we need= to keep things *simple as possible* at all times

= 4. I think the solution you're looking here for is better *education* t= o the end-users, on what the implications of X or Y are .. rather than chan= ging the language itself .. so the merits of your proposal are good, in tha= t it helps the end-user understand the system better .. it's just the s= olution you're proposing here just isn't it (so far).
=C2=A0

Used correctly, it absolutely does. Used incorrectly, it can actually end up *hiding* errors.

I've seen lots of cases where code like this:

some_function_expecting_int($_GET['foo']);

Gets changed to this:

declare(strict_types=3D1);
some_function_expecting_int( (int)$_GET['foo'] );

Even in PHP 7.0, the first version is actually *stricter* than the second, because explicit casts never fail, but parameter coercion (mode 0) always failed for strings like "hello"; a= s of 8.0, it also fails for strings like "123foo" and "&quo= t;.

And this is exactly the kind of code that coercive type hints were intended for - HTTP is a text-based protocol, so most PHP applications are dealing with string input and output *all the time*.

One of the things the language badly needs, and I have been trying to come up with a proposal for, is strict type casts, so that this code can actually be written safely but still concisely.


Regards,

--=20
Rowan Tommins
[IMSoP]
--000000000000afc31d061b62d591--