Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129941 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 7CB121A00BC for ; Tue, 27 Jan 2026 12:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769516047; bh=N6O+uJwO/zUsJ3ICAO7YuOw2ju/CeLaEBNQkRTI7ct4=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=dSnW3esBFF1DM0s3MATWbqUOU0oGoGmr1+MOXtCG1Chta0UzZSbqKcJL7kttavSK7 h1u1fIllRdmoEiZRCDwKRIwloKEl7sA3ytD72ByEqZkvZkSJHKmIfcleBc2169OBhu LXPHFfRZ/vY3LnuAw3jjRw3C+vkTryDCyN0oxdK4pRlXQ+4acHix4LKMy1NZ0gNJ6+ 5nf3sbY7J6D9jDLy8kNqCuWZly8uHnQbv0DplaJLUvFblEsIY42L5RIGiwvcfESk1t hi2XAwZNjW79Bu+CgDPjB4i1sLjmRDOuvZQWitJl+V7BfWfmh4gIy1/rW8BAi+xcdy mGEHRc4RQp/vA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C21ED18003B for ; Tue, 27 Jan 2026 12:14:06 +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-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 12:14:06 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id F048EEC00E7; Tue, 27 Jan 2026 07:14:00 -0500 (EST) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Tue, 27 Jan 2026 07:14:00 -0500 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=fm3; t=1769516040; x= 1769602440; bh=N6O+uJwO/zUsJ3ICAO7YuOw2ju/CeLaEBNQkRTI7ct4=; b=H 9X1DNzEmYTGYUW/D4/vO7gXrj5MarLNsycJP1beojMSWq2N71cTULPm2cwhbrL6v 5/IpcNA843cTYysCOOP8F8nPiNAPztyrDdKH/lKDLy5vR6y4Y3AshKYfeFoZi3o7 VNZZkd4/hJZLvpkjH4fxEAJqS86iJZIpJqvOyN/BRIWXp3L7OStG49CiqH8GxBd+ gCFRv+bVwFVrWTZiZR1hIpZhNiI84BVwGvFCQoNx5X6DhiaAZ7T0uoBlFFKY7PS/ IRisdciyl3HDt2xePj6rnIeNZl1z+aisMRZcYFrEehQfNETILV84CTpr7+EaZYTt Ue74Grp1fBpRjKjUJ3W9A== 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=fm2; t= 1769516040; x=1769602440; bh=N6O+uJwO/zUsJ3ICAO7YuOw2ju/CeLaEBNQ kRTI7ct4=; b=Q2zXlfGeRIMbQLkXtun2oZY8BTj9LTngCXw6GcUl40r26R/HaL+ 9NNJUrikaSbA4+ToBLPcwv4RUWqkyjfYtET3ljdkk6X6uixx6t1KlvYFpzXeSe+Z BGihggH14PCgoC5PEKl/68oNvjN8lw2zOaaZG5EYRP4iTr663ou/KOZwdnOIZf0E V3QTKuFOoQsAsBo/sh1pUvxWffA3707yy+HDDfTO7MBCYphThbSJNq+sUNc9jcUe hz5BVDuuZJxMSTVUCT4Mnsq1q21QNBNMtHN2hrmeB2+C/YASejEkDtYcTKc755JP bArMCFFFN3SqRTRCGQtK5uZTPRnR1xie0Mg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduiedthedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfn rghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtth gvrhhnpefhveetveeuhfejiedthefhveegvddvgfdujeevudekfffhhedvgfffgedvleef ffenucffohhmrghinhepfehvgehlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgs pghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprghlvgigrd gurghusghoihhsodhphhhpsehgmhgrihhlrdgtohhmpdhrtghpthhtohepkhhjrghrlhhi sehgmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrph hhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8B7B5182007E; Tue, 27 Jan 2026 07:14:00 -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 13:13:40 +0100 To: Lynn , "Alexandre Daubois" Cc: "PHP internals list" Message-ID: <411b1964-eacd-475f-a9f5-2a954b6d30df@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=225418ba83ce434282f0442e0f59a6e1 From: rob@bottled.codes ("Rob Landers") --225418ba83ce434282f0442e0f59a6e1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jan 27, 2026, at 12:54, Lynn wrote: >=20 >=20 > On Fri, Jan 23, 2026 at 3:17=E2=80=AFPM Alexandre Daubois > wrote: >> I understand the concern about legacy code. However, if code relies on >> `(int) "123abc"` silently returning `123`, this represents a data >> integrity issue that would benefit from being made explicit. The >> deprecation period exists specifically to help identify and address >> these cases. >>=20 >> > Does this behavior als affect parameters being passed in a non-stri= ct fashion? Because then I don't see a realistic migration path within t= he next decade for this application. >>=20 >> This behavior already exists and forbids such casts, see >> https://3v4l.org/WQJPv#vnull. >=20 > Thanks for your reply!=20 >=20 > I've given it a bit more thought and while I 100% agree with the reaso= ns given, I'm still afraid this change is too big of an unknown break. I= do not have voting power, so all I can give is my opinion. >=20 > As an alternative, what about this? It could be the best of both world= s where the new behavior is explicit: > ```php > $var =3D (int) '123test'; // still works, nothing changes, becomes an = `(int) 123` > int $var =3D '123test'; // follows the proposed rules, errors because = it's not a value that's a valid integer > int $var =3D '123'; // works because it's a valid integer format, beco= mes (int) 123 > int $var =3D (int) '123test'; // becomes (int) 123, existing behavior > ```=20 > This way nothing breaks and the casting remains what it is, but we can= still enforce correct types. I know the 3rd line might be controversial= , but it makes it an opt-in instead of opt-out feature and errors can be= thrown as of day 1. >=20 > Bonus: > ```php > int|null $var =3D '123test'; // could result in `null` instead of thro= wing, similar to the Enum tryFrom. >=20 > // could enable > MyEnum $foo =3D '123test'; > MyEnum|null $bar =3D '123test'; >=20 > // translates to > $foo =3D MyEnum::from('123test'); > $bar =3D MyEnum::tryFrom('123test'); > ``` >=20 > `from` and `tryFrom` could be taken as base for custom cast functions,= but that's probably a whole different can of worms. I kinda like this idea, but it would be nice to follow the same rules we= have with function calls, thus=20 int|null $var =3D "123test"; (https://3v4l.org/C0uaK/rfc#vgit.master) would be a TypeError. Less special cases means less bugs and less things= to remember. =E2=80=94 Rob --225418ba83ce434282f0442e0f59a6e1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Tue, Jan = 27, 2026, at 12:54, Lynn wrote:


<= div class=3D"qt-gmail_quote qt-gmail_quote_container">
On Fri, Jan 23, 2026 at 3:17=E2=80=AFPM Alexandre= Daubois <alex.dauboi= s+php@gmail.com> wrote:
I understand the concern about = legacy code. However, if code relies on
`(int) "123abc"` sile= ntly returning `123`, this represents a data
integrity issue = that would benefit from being made explicit. The
deprecation = period exists specifically to help identify and address
these= cases.

> Does this behavior als affect pa= rameters being passed in a non-strict fashion? Because then I don't see = a realistic migration path within the next decade for this application.<= /div>

This behavior already exists and forbids such= casts, see

Thanks for your reply! 

I've given it a bit more thought and while I 100% agree = with the reasons given, I'm still afraid this change is too big of an un= known break. I do not have voting power, so all I can give is my opinion= .

As an alternative, what about this? It = could be the best of both worlds where the new behavior is explicit:
```php
$var =3D (int) '123test'; // still works, nothin= g changes, becomes an `(int) 123`
int $var =3D '123test'; // f= ollows the proposed rules, errors because it's not a value that's a vali= d integer
int $var =3D '123'; // works because it's a valid in= teger format, becomes (int) 123
int $var =3D (int) '123test'; = // becomes (int) 123, existing behavior
``` 
Th= is way nothing breaks and the casting remains what it is, but we can sti= ll enforce correct types. I know the 3rd line might be controversial, bu= t it makes it an opt-in instead of opt-out feature and errors can be thr= own as of day 1.

Bonus:
```php
<= div>int|null $var =3D '123test'; // could result in `null` instead of th= rowing, similar to the Enum tryFrom.

// could e= nable
MyEnum $foo =3D '123test';
MyEnum|null $bar =3D= '123test';

// translates to
$foo =3D= MyEnum::from('123test');
$bar =3D MyEnum::tryFrom('123test');=
```

`from` and `tryFrom` could be ta= ken as base for custom cast functions, but that's probably a whole diffe= rent can of worms.

I k= inda like this idea, but it would be nice to follow the same rules we ha= ve with function calls, thus 

int|null $va= r =3D "123test"; (htt= ps://3v4l.org/C0uaK/rfc#vgit.master)

wo= uld be a TypeError. Less special cases means less bugs and less things t= o remember.

=E2=80=94 Rob --225418ba83ce434282f0442e0f59a6e1--