Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129938 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 3BEC71A00BC for ; Tue, 27 Jan 2026 09:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769506655; bh=4jx4dYfrNAl16LOxKqyLGmIyPHKc2etBXuF17g4m70E=; h=Date:From:To:In-Reply-To:References:Subject:From; b=ifw8i6vb6gmhsuN9orQF+iliBIkB8cNoW2zsKQnr2N8L3t/qks25FznZ6hNkwJeL/ dCqo785ody9hEMavjIiCh38azCMU9GqcUQ7krTTx1fFPRdUUbA6+EZeyFNoXg+rkRS 6M9eg9sTjKdNhI0el9hyoG7oM4hFvwuFdcOVooQwhLlHlrcawub3z9J6a7AiVpwXOs iC41R+4OWDFRDFK3vFypyiR1OszocBNPyxHI9D7p2NUyO3HDvUQQs7kKz3Bb88XPLq 6CTf04oYOkftLH+QmatFw2p/7B2aBnS0FLYccHMvW+k9vbTMVJmUJkbN88BA87Sdhb VbaXWo/zLDVbw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D1B2418003B for ; Tue, 27 Jan 2026 09:37:34 +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=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-b3-smtp.messagingengine.com (fout-b3-smtp.messagingengine.com [202.12.124.146]) (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, 27 Jan 2026 09:37:24 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 47B7D1D0016D for ; Tue, 27 Jan 2026 04:37:19 -0500 (EST) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Tue, 27 Jan 2026 04:37:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=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=fm3; t=1769506639; x=1769593039; bh=4jx4dYfrNA l16LOxKqyLGmIyPHKc2etBXuF17g4m70E=; b=Wi3XFwotLDhVxVwoHWIQBxR7fg nSDnRq/o4x15y8UuRk5Y+Jku6Qrzm8HRdpkaFEKGJe4OcOhf2V9Kch/XS7yWwNgS nqwNDI5Qztt+L3QPvhp2JaN06eqiOfB5nFpcqEiUX1qXb6Nw/rRcMHnZeQIDdUi7 rFGwz01pEoZrg17qXkLQQ1Q96oJ4bxwaXck8PDzG+WTmwlcK0dM1+PUcpc+L8ZCr BoWSmukk9dds6suzxouiZSBC/VyE6ku5n8TBWExgeuyvCSO8Ffq0o8ekNnDIcn7j M4OLYD1sO6jXeVVoLPkfgkZEKIQMippprJ71SHktLPt7CTZmECaeHsBAn+lQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm2; t= 1769506639; x=1769593039; bh=4jx4dYfrNAl16LOxKqyLGmIyPHKc2etBXuF 17g4m70E=; b=J15WGQiBqgI315kU5VYV+9mPTtCgxwYwIQyw9hAgveJwDTM3xYo sp25+WzdP25AJsn8GEGnj524VEbGxcnovxbCpFYr76Qjz3aiolvvrImacMt3THcz +QVXQs2YtmcrXEFOBSdOgjI82m4+UM5TGOr7n1/KNiK/S7Rck3YEx/qBrf5t2KF2 fqhSzfdt1fKqHXptnmWBD6LaLAmxK9JozdAgHq9io3IxtaCvDs4UHNigNYH/6ozR LOsoAuAJ0rnoZCtY7gx6SBaDUcm2jvVRbYOd/3e6ddl0/aSK+h7UY+jFkd/AMIAu PzzfXfWZIsFn9eQlY+ojDA+9OytxJA2loEw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduiedtudekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvkfgjfhfutgesrgdtreerre dtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggu rdgtohguvghsqeenucggtffrrghtthgvrhhnpeelkeehtdfgfefhleeilefggeeihfekvd elfeejtdfflefhheehfffgudetuddutdenucffohhmrghinhepphhhphdrnhgvthenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsoh htthhlvggurdgtohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id A2CBB182007A; Tue, 27 Jan 2026 04:37:18 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: A2uxYA7CYK-V Date: Tue, 27 Jan 2026 10:36:58 +0100 To: internals@lists.php.net Message-ID: <94dd62b3-7e5c-4162-9bef-042498ff7059@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] Deprecate Fuzzy Type Casts and Allow Stringable in Strict Mode Content-Type: multipart/alternative; boundary=d93610e49f4449098d9cab6d1b4501fb From: rob@bottled.codes ("Rob Landers") --d93610e49f4449098d9cab6d1b4501fb Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, Jan 23, 2026, at 11:48, Alexandre Daubois wrote: > Hello everyone, >=20 > Before going further with our already under discussion RFC about > nullable casts, Nicolas Grekas and I would like to present this new > RFC about deprecating fuzzy casts, and adding support for Stringable > in string parameters when using strict mode. >=20 > RFC: https://wiki.php.net/rfc/deprecate-fuzzy-casts >=20 > Thanks, >=20 > =E2=80=94 Alexandre Daubois >=20 This is interesting. As a user of non-strict mode, I rarely need casts. = That being said, after working on tons of strict-mode code bases, this i= s exactly the footgun I use to show how strict-mode is actually bad for = their code base: I remove the casts and turn off strict mode, and the ap= plication actually crashes because it was silently handling bad inputs a= ll over the place. Here's a pretty good example I saw a few weeks ago: $newBalance =3D (int)$walletBalance; $wallet->store($newBalance); /* ... later ... */ $log->append($walletBalance); // which takes a string Now, if this string is something like "1000; drop table money" and there= isn't proper injection protection... you're in for a bad day. Without strict mode: $wallet->store($walletBalance); // TypeError: cannot coerce string to int That being said, I think the more proper solution is to simply remove st= rict mode instead of making casts stricter. Why? Sometimes you actually = do need to use a cast to force a specific type, and you want to use the = loss of information. Like I=E2=80=99m pretty sure casting a float to an = integer is faster than calling floor(), and you end up with an integer, = not a float. Secondly, to properly use strict-mode, you have to religiou= sly cast everything, which hides errors that=E2=80=99d otherwise appear.= But getting rid of lossy casting seems like trying to apply a tournique= t to the wrong limb. =E2=80=94 Rob --d93610e49f4449098d9cab6d1b4501fb Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Fri, Jan = 23, 2026, at 11:48, Alexandre Daubois wrote:
Hello everyone,

B= efore going further with our already under discussion RFC about
nullable casts, Nicolas Grekas and I would like to present this new
RFC about deprecating fuzzy casts, and adding support for String= able
in string parameters when using strict mode.
<= br>
Thanks,

=E2=80=94 Alexandre Daubo= is


This is interest= ing. As a user of non-strict mode, I rarely need casts. That being said,= after working on tons of strict-mode code bases, this is exactly the fo= otgun I use to show how strict-mode is actually bad for their code base:= I remove the casts and turn off strict mode, and the application actual= ly crashes because it was silently handling bad inputs all over the plac= e.

Here's a pretty good example I saw a few wee= ks ago:

$newBalance =3D (int)$walletBalance;
$wallet->store($newBalance);
/* ... later ... */
$log->append($walletBalance); // which takes a string

Now, if this string is something like "1000; drop tabl= e money" and there isn't proper injection protection... you're in for a = bad day.

Without strict mode:
$wallet= ->store($walletBalance); // TypeError: cannot coerce string to int

That being said, I think the more proper solu= tion is to simply remove strict mode instead of making casts stricter. W= hy? Sometimes you actually do need to use a cast to force a specific typ= e, and you want to use the loss of information. Like I=E2=80=99m pretty = sure casting a float to an integer is faster than calling floor(), and y= ou end up with an integer, not a float. Secondly, to properly use strict= -mode, you have to religiously cast everything, which hides errors that=E2= =80=99d otherwise appear. But getting rid of lossy casting seems like tr= ying to apply a tourniquet to the wrong limb.

=E2=80=94 Rob
--d93610e49f4449098d9cab6d1b4501fb--