Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123721 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 E26871AD8EA for ; Fri, 21 Jun 2024 09:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718961343; bh=6mv7flsE686X56VW69t86qzna74PdpATE4DzLyUjHsI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RiAOx0MVb0wZW3EyhHcr7g7a9CsCkpFj8IRZBffuWUEPco4slsynwTPL1gYUn/8OT TfGoK5gE1tXlvZIsdGtJ7Sa+n/ClK9g3LrtIhkfNW96LXx1JzpfBA0gKnkcNqHMQAb 1njpZExP6XhJ0i7ZBwXWMhbWQbFBs8+OrMKba5lnjD+YCOYJs8Mc8Y6GrGBOqf4HNG IBwlgPdKfUDwqzS/MfksUa3QO5Sb1rchRZ7JIUhxj7h2d+QMRnMS73+zxnidY7ZOoZ ByebwkmgQctLUr0omlP5K6agn3bw5X0/2YRCILWlEvabqrqPxqq8x25pgPVtsoFW7i stxoP0v9mSs8w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A58501806C0 for ; Fri, 21 Jun 2024 09:15:40 +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_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-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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:15:37 +0000 (UTC) Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52b7ffd9f6eso2054335e87.3 for ; Fri, 21 Jun 2024 02:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718961262; x=1719566062; 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=8z2Bu9js0WBY9JFcx1QEz1lBvLqdvCByMqQVASH6WA0=; b=WCLPK2PE24Q85lzQ/OIZXZX8XIjw5XzIqmWkev8PMjpIGGR6n71dyWmW3EWg7c8Yw+ 7GqAb47xbvy/gnNlwTKFyA+GMDRCU1aHfSBAnQFVMiO/1PlhFlN9w4E1s9oG1omB7F5A GBwwCX7Nc1/knHn7apko/rTHvFZ+ot2k3AAH0gbYqGtX1fz9ip8m0GnMfvYZxP9z4Ykl sv+sp3G/ihtPgprovtEX15hZFeuCF8QKx3f8uPYpgcTMdtP7wJnd49H7YVybFnA8gys/ G+RhglTtqiCNDblj0mfNbgHNfx2AOTc2SArWzu2AdQEIfiEXgi38/ISbAOqxBDr6JjmY te2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718961262; x=1719566062; 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=8z2Bu9js0WBY9JFcx1QEz1lBvLqdvCByMqQVASH6WA0=; b=IfH5hAc1PGYPtQP8IQCXMnkJrkRwhmV+a7QMptZ+7tsXLozZxCugAdYJTyYHVCFQMS bO1qPsP2lu3m9xOA7l1GQMFb2wNFaMq7uskpzsliroNAZ2WiO7TcfeNY/F335YdBfVYr NvcFR07blIoYUkClh6zgAmTTO3Fb8JfWHKXYiABJJJTZKD9AYm05858owBgGDIHRNWWo S7YEiQRWHheLXzGXddVyBy4KvDVPL0ifO0R9nuoSWhQYIQ8UbwYeT1MApapiNW3ojAgS 6j8DG3E1UcggQOXcsvHn+0GOKVzZB5FIy4pn4jYo+rEgitO+fAFj9XUgLTyKT+pr5/ct O8LQ== X-Gm-Message-State: AOJu0Yyu/aocx1FXsGZn2xeDHjDliS3p1ezOtiSSGH1ATW7Qrb8B6tM4 lYQa/gqU8JIE/YauYHPDtdHaXHpsNR2skfjpaO03ygYcyKHnPmjrNsAGVIwwLL3VpiVssOxy1RB ZUwXHHpr0/Xm/b10o1t9iQIx6/L0Xt92L X-Google-Smtp-Source: AGHT+IH2QNNXL4VnfyyWvmtICOLhGBWd/eC+evqhUOJvTGhTByYS/jgCqqjYOyea1m9vDLSqUD5rjI4O7ke2ycCDvSw= X-Received: by 2002:a05:6512:690:b0:52c:cca8:a9fb with SMTP id 2adb3069b0e04-52ccca8aa1bmr5046648e87.42.1718961261628; Fri, 21 Jun 2024 02:14:21 -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: Date: Fri, 21 Jun 2024 10:14:09 +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="00000000000061dcac061b62dba0" From: dragoonis@gmail.com (Paul Dragoonis) --00000000000061dcac061b62dba0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 21, 2024 at 10:12=E2=80=AFAM Paul Dragoonis wrote: > > > On Thu, Jun 20, 2024 at 11:54=E2=80=AFPM Rowan Tommins [IMSoP] < > imsop.php@rwec.co.uk> 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, > I meant Hey Robert, but half replying to Rowan's suggestions too. > > 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 like "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 a= re >> 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, >> >> -- >> Rowan Tommins >> [IMSoP] >> >> --00000000000061dcac061b62dba0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Jun 21, 2024 at 10:12=E2=80= =AFAM Paul Dragoonis <dragoonis@g= mail.com> wrote:


On Thu, Jun 20, 2024 at 11:54= =E2=80=AFPM Rowan Tommins [IMSoP] <imsop.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,

I meant Hey Robert, but half replyi= ng to Rowan's suggestions too.
=C2=A0

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 adding more words and complexity to it

2. adding the = word "coerce" or "coercion" to a thing is really not go= od from a DX (developer experience) perspective. It will not add clarity it= will add *confusion*... "What is this coersion thing I've never h= eard 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 a= nd likely know what coersion=C2=A0is

3.1 PHP's= strength is that it's beginner friendly and by that I mean just rememb= er a significant portion of our userbase=C2=A0are Wordpress developers (and= Drupal / Magento alike) .. and many WP devs won't have even heard of D= ependency 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 *educa= tion* to the end-users, on what the implications of X or Y are .. rather th= an 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 jus= t the solution you're proposing here just isn't it (so far).
<= div>
=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]
--00000000000061dcac061b62dba0--