Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127569 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 lists.php.net (Postfix) with ESMTPS id 73DA01A00BC for ; Tue, 3 Jun 2025 17:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748972302; bh=UVnMtKAND6mv/Iktaqo5HvORGa7RgR4/3UtlDjjz0xQ=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=E004ECDSZRiac9xSfNd/pX1CQhPvwfFs0PlevkfqhabpbFtBoS1l9wTj83fNr0DIj u7HiLnA9ctHi0TFLpRHhzJFXX9b7LpybC5AM965sr0F1u1+usMV2n951Z24AvAK0j2 uFVDcsx9/4eaoWRvPzAM5WEWJ8C6zhOxtkgpsA68u5su0AQgBB0SUVAp7S5UUxH7xp SDv9CPuzvJcuYDqdQGg2LcSEY4+UVJMEU4Zb8FIZWShJOgmtlVMetBjQARuai+kjhW kFeqlGJmFTRZze82iAG4Hgq3HWOVZ4WwaUMHPEmQG29/6pdizXFq1VGXcWnT4/BnsF 9TxlShybVolMg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D559A1805BA for ; Tue, 3 Jun 2025 17:38:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-b5-smtp.messagingengine.com (fout-b5-smtp.messagingengine.com [202.12.124.148]) (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 ; Tue, 3 Jun 2025 17:38:20 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 6CCE61140136; Tue, 3 Jun 2025 13:40:24 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Tue, 03 Jun 2025 13:40:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=1748972424; x= 1749058824; bh=UVnMtKAND6mv/Iktaqo5HvORGa7RgR4/3UtlDjjz0xQ=; b=Z aLgk9s0MaZbiPw7xbINV5jGTzQ4rhpoCvoYW1NLCa0/2Z7req/xjNCeaPe46xBqp nYnYKD+RtmLIQ+SSO6xQFVouM6RGWAZKYbqH7zdgwEjGU2f8CVjMfdPHLdqtWkmv Xsl9GEAi3q399GrXaSmzrcleCDQI0kGXEQCc0U0jVIEVKyBKIOPvCuGdN3ssKWhc g5xTzAY/dal99mgSQjPTIeVdXiufrpItqwzZktPlEYmYC1oQ5U0uu7SA8i12ybZH 64JfZ3htjYKT+pe+vPYv0OAWdbgQAqe6NDRnvWieDIaYwEOv9iQuuo+1jhaP8JMX p/6yHx33ctsjBYTaPEwOw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1748972424; x=1749058824; bh=UVnMtKAND6mv/Iktaqo5HvORGa7RgR4/3Ut lDjjz0xQ=; b=NXmCVGwIYSJlWNClmMpy3EJ/e+Mjm0iaNF9WdZTT2ysp8xkmbXp wHgOuk6Orgphql6Xbwae6xt+1howmZpRxKykOuW60YEgLJwFDVeWWESN6g+rdZVs YLEbdDpVaQeasIrKBQaM8znjp4RhCeQeXoNgQiRPDgM41GzNHjucbn7wA4yxiFft 6DAx8mOHRwv2tP1nE16cLxfdoThMuZt8u21hMNljBbsnzkATW1ltktmE5GXbLZAa OnrKMgFLEhPbbkyGtVewCYQznmJPUZes0ZyoVUu54klcD2z34yP/IemNQVfv5z6m X0DGuJ1ZB/in+FpwZaUMGvVRCXKGALQOP3Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdekiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggfffhvf evkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcu oehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpefffeduve dvfeektdekhfdvjedvhefggfetkeeiieeihfeiueeuteegheeltddtleenucffohhmrghi nhephihouhhtuhdrsggvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtohep vddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlshesghhpsg drmhhovgdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id BDA361820064; Tue, 3 Jun 2025 13:40:23 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T93bbdd38331b9ecb Date: Tue, 03 Jun 2025 19:39:21 +0200 To: "Gina P. Banyard" Cc: internals@lists.php.net Message-ID: In-Reply-To: References: <3Yl0UGauXmKqk7s7Hqbv6iaXru-hZHf8Wj6VjwwihgRSaqZo5EZ2ndsOle-ae41C-lvnirynWt6PpuD7UJPL0zPCw18QHFE81Eb--fiiEbc=@gpb.moe> Subject: Re: [PHP-DEV][RFC] Deprecate type juggling to and from bool type within the function type juggling context Content-Type: multipart/alternative; boundary=9491128bafb84b1a9140db855e5403b1 From: rob@bottled.codes ("Rob Landers") --9491128bafb84b1a9140db855e5403b1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jun 3, 2025, at 18:19, Gina P. Banyard wrote: > On Monday, 2 June 2025 at 22:05, Rob Landers wrote: >> No offense, but this feels like it was written by someone who doesn=E2= =80=99t use non-strict mode very often. >=20 > As yes, saying this to me, someone that is known to have said on stage= , multiple times, during talks that > > The strict_types declare was a mistake. > Something I even reiterated 7 weeks ago at a Drupal conference. [1] > It would be nice that you don't make assumption about how I write PHP = code, as I use weak and strict mode extensively while being annoyed with= both modes constantly. > Moreover, even if one uses strict mode one must still know how weak mo= de behaves as closures/callables do not follow the typing mode in which = they have been declared. Hey Gina, As mentioned, my intent wasn=E2=80=99t to offend. My goal was to tell yo= u how it read, from my perspective, whether you intended it to or not. A= s in someone trying to force everyone using weak mode to use strict mode= . I=E2=80=99m really sorry that it came across that way, though. >=20 >> The rules around coercion are pretty simple and well documented. >=20 > Considering I have given *multiple* talks about PHP's type system and = type coercions rules, many people do *not* find them simple or intuitive= and get bitten by them constantly. That is a fair point. I=E2=80=99ve seen the same confusion among juniors= (and sometimes seniors!) over the years. My sense, though, is that some= confusion is less about PHP=E2=80=99s type system itself and more about= the unique way PHP handles requests compared to other languages. In mos= t languages, frameworks insulate you from the raw request data and make = explicit choices about parsing and typing. In PHP, by contrast, you ofte= n get the raw bytes, and it is up to you (or your framework, hopefully) = to massage that into proper types=E2=80=94which can lead to surprising b= ehaviours if you=E2=80=99re not careful. I think sometimes people bring expectations from other ecosystems (where= , say, the string =E2=80=9Cfalse=E2=80=9D might have special meaning) an= d are surprised when PHP treats =E2=80=9Cfalse=E2=80=9D like any other n= on-empty string. Maybe that mismatch is the root of a lot of frustration= s? Curious if you see it the same way, or if there is something more fundam= ental in PHP=E2=80=99s type rules you think causes the confusion? >=20 >> Further, this makes a ton of shorthand nearly impossible =E2=80=94 th= e manual casting to bool in strict mode is one of the most annoying cast= s someone has to do (and people screw up order of operations all the tim= e leading to subtle bugs worse than coercion). Bringing this into all of= php is probably not a good idea.=20 >=20 > It would have been nice to showcase some of these shorthands rather th= an hiding them behind some sort of mystic as a counterargument. > I really would like to know in which cases you use non-boolean values = as argument to boolean parameters. > People creating more subtle and worse bugs due to arbitrary casting is= precisely why I want to unify the typing modes, so it's good to know th= at we think somewhat the same. // From a real codebase (sanitized): $shouldStop =3D (bool)($result =3D $service->doSomething($input)) && $re= sult->isError(); This pattern comes up a lot in strict mode: you have to be extra careful= with casts and parentheses, or you can end up with subtle bugs like acc= identally always returning true/false, or masking null/error values. In = looser modes, this just =E2=80=9Cworked=E2=80=9D, but strictness can mak= e it surprisingly easy to trip up. In my experience, a lot of =E2=80=9Cnon-boolean to boolean=E2=80=9D case= s are legacy patterns or integrations, but sometimes we=E2=80=99re deali= ng with values that can be =E2=80=9Cfalsy=E2=80=9D in multiple ways (emp= ty array, 0, '', etc.). Sometimes we=E2=80=99re adapting legacy code or = writing wrappers that need to accept a wide range of inputs. The problem, in my view, is that *forcing* strictness everywhere makes t= he simple, idiomatic code that worked in PHP for years much more verbose= ; and potentially more error-prone if the developer isn=E2=80=99t carefu= l with casts or operator precedence. >=20 >>> Type juggling of strings to bool is similarly error-prone. The strin= gs "" and "0" are converted to false, but "false", " ", and other string= s which an (int) cast converts to 0 are coerced to true. >>=20 >> If I understand correctly, you are saying it is weird why the bytes 6= 6 61 6C 73 65 are =E2=80=9Ctrue=E2=80=9D and 30 is a special case, but n= ot 20? If I remember my history correctly, 30 is special-cased because f= orms used to send =E2=80=9C0=E2=80=9D on checkboxes (if it sent it at al= l; it changed from decade to decade). >=20 > I know the reason why we coerce the string "0" to false. > But it is very atypical compared to every other programming language, = so yes it is "weird". I will 100% agree with you about "0" being *false*. It was a handy short= cut 20 years ago, but these days it creates more confusion than it solve= s. >=20 >> I don=E2=80=99t see the benefit of removing this implicit coercion. >=20 > The statement is noted. >=20 >=20 > Regards, >=20 > Gina P. Banyard >=20 > [1] https://youtu.be/85fgBcV3BuM?t=3D2832 =E2=80=94 Rob --9491128bafb84b1a9140db855e5403b1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Tue, Jun 3, 2025, at 18:19, Gina P. Banyard wrote:<= /div>
On Monday, 2 June 2025 at 22:05, Rob Landers <rob@bottled.co= des> wrote:
No offense, but this feels like it was written by someone who d= oesn=E2=80=99t use non-strict mode very often.
As yes, saying this to me, someone that is known to have sa= id on stage, multiple times, during talks that
> The = strict_types declare was a mistake.
Something I even re= iterated 7 weeks ago at a Drupal conference. [1]
It would be n= ice that you don't make assumption about how I write PHP code, as I use = weak and strict mode extensively while being annoyed with both modes con= stantly.
Moreover, even if one uses strict mode one must still= know how weak mode behaves as closures/callables do not follow the typi= ng mode in which they have been declared.
=

Hey Gina,

As mentioned, my = intent wasn=E2=80=99t to offend. My goal was to tell you how it read, fr= om my perspective, whether you intended it to or not. As in someone tryi= ng to force everyone using weak mode to use strict mode. I=E2=80=99m rea= lly sorry that it came across that way, though.

=
T= he rules around coercion are pretty simple and well documented.

Considering I have given *multiple* talks = about PHP's type system and type coercions rules, many people do *not* f= ind them simple or intuitive and get bitten by them constantly.

That is a fair point. I=E2=80=99= ve seen the same confusion among juniors (and sometimes seniors!) over t= he years. My sense, though, is that some confusion is less about PHP=E2=80= =99s type system itself and more about the unique way PHP handles reques= ts compared to other languages. In most languages, frameworks insulate y= ou from the raw request data and make explicit choices about parsing and= typing. In PHP, by contrast, you often get the raw bytes, and it is up = to you (or your framework, hopefully) to massage that into proper types=E2= =80=94which can lead to surprising behaviours if you=E2=80=99re not care= ful.

I think sometimes people bring expectation= s from other ecosystems (where, say, the string =E2=80=9Cfalse=E2=80=9D = might have special meaning) and are surprised when PHP treats =E2=80=9Cf= alse=E2=80=9D like any other non-empty string. Maybe that mismatch is th= e root of a lot of frustrations?

Curious if you= see it the same way, or if there is something more fundamental in PHP=E2= =80=99s type rules you think causes the confusion?


Further, this makes a ton of shorthand nearly impossible =E2=80=94= the manual casting to bool in strict mode is one of the most annoying c= asts someone has to do (and people screw up order of operations all the = time leading to subtle bugs worse than coercion). Bringing this into all= of php is probably not a good idea. 

It would have been nice to showcase some of these shorthands ra= ther than hiding them behind some sort of mystic as a counterargument.
I really would like to know in which cases you use non-boolean = values as argument to boolean parameters.
People creating more= subtle and worse bugs due to arbitrary casting is precisely why I want = to unify the typing modes, so it's good to know that we think somewhat t= he same.

// From a rea= l codebase (sanitized):
$shouldStop =3D (bool)($result =3D $se= rvice->doSomething($input)) && $result->isError();

This pattern comes up a lot in strict mode: you have t= o be extra careful with casts and parentheses, or you can end up with su= btle bugs like accidentally always returning true/false, or masking null= /error values. In looser modes, this just =E2=80=9Cworked=E2=80=9D, but = strictness can make it surprisingly easy to trip up.

In my experience, a lot of =E2=80=9Cnon-boolean to boolean=E2=80=9D= cases are legacy patterns or integrations, but sometimes we=E2=80=99re = dealing with values that can be =E2=80=9Cfalsy=E2=80=9D in multiple ways= (empty array, 0, '', etc.). Sometimes we=E2=80=99re adapting legacy cod= e or writing wrappers that need to accept a wide range of inputs.
<= div>
The problem, in my view, is that forcing stric= tness everywhere makes the simple, idiomatic code that worked in PHP for= years much more verbose; and potentially more error-prone if the develo= per isn=E2=80=99t careful with casts or operator precedence.


Type juggling of strings to boo= l is similarly error-prone. The strings "" and "0" are converted to fals= e, but "false", " ", and other strings which an (int) cast converts to 0= are coerced to true.

If I underst= and correctly, you are saying it is weird why the bytes 66 61 6C 73= 65 are =E2=80=9Ctrue=E2=80=9D and 30 is a special case, but not&nb= sp;20? If I remember my history correctly, 30 is special-cased because f= orms used to send =E2=80=9C0=E2=80=9D on checkboxes (if it sent it at al= l; it changed from decade to decade).

<= div>I know the reason why we coerce the string "0" to false.
B= ut it is very atypical compared to every other programming language, so = yes it is "weird".

I w= ill 100% agree with you about "0" being false. It was a handy sho= rtcut 20 years ago, but these days it creates more confusion than it sol= ves.

=

I don=E2=80=99t see the benefit of removing th= is implicit coercion.

The statemen= t is noted.


R= egards,

Gina P. Banyard

=

=E2=80=94 Rob=
--9491128bafb84b1a9140db855e5403b1--