Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129940 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 558731A00BC for ; Tue, 27 Jan 2026 11:54:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769514879; bh=6ljhRXbB4Fwzv3uMDuN+yFNTuGsar0eJPdydHer4EWI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EoIB3v0eXRGp0S+x0t/+LfzArTPqI2arDt0lr65vbDI1+w7JuBT5DDWhRTR4u9MTi 6kmEIZdYR+dg2XUpbGnBxBgHOX7UaVVB2GyJ+ztvgCnfBT+r1BwFrN18tGQlBz5/8x bGPb7quaxURxIW66zv9nzly3kIudlqay9sdE5zbvsY1LoyPjWmXwL0u2ISTeZFJ4Ll 7q6hWjPp+CCGidGc1nQFTzChhdGnzLud9Ysde0db76Y1CW4GnItx1hquy5cskoKj7g 5TVg5vZkhh58vdFhqqhmy+eeJlM5IAAgE12XxQTw8FB9B8C6UVA3hZVEDZUwU5YInd qr1YNtYZvV9EA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2B46B180041 for ; Tue, 27 Jan 2026 11:54:39 +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=2.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FORGED_GMAIL_RCVD,FREEMAIL_FROM,FREEMAIL_REPLY,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 11:54:38 +0000 (UTC) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-59dd22b9895so6665735e87.0 for ; Tue, 27 Jan 2026 03:54:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769514872; cv=none; d=google.com; s=arc-20240605; b=ex2zRPES7Ai/KiJTGuZy1gKwQcY2jyOS8ggJrhQSZwmnevMhAJgRttsZh4Rq3u/17B 9Bn3pdgkj3e9cRo/WTma4rP0Gg65yXmBhBmoFikzd9oabJ604PrnsYTNVaUM3KM9imHh NX84aeiD90u/ls/u6y4PAVYO4yA1SH527EHul9hwQ7gtXoHzS+w2T7Pl/uXXz1ZViSPV 8dMVSXLdm1JCJzaaaBzGOqMdd1zJm2951kmfxoBmDHodyNXQOGbRuiJhZqcR+pWsNryc zD8mpgkKOPR9ou2rMJeAl5WJUuVfdtzO2BO5ckRQJrd2v96s5nmmutGAsRNHGa4ea7Oy Q/4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=6ljhRXbB4Fwzv3uMDuN+yFNTuGsar0eJPdydHer4EWI=; fh=l07cGoIg3TRylNOf7lMYEJBLdTFa5KOl1A4mid5ExIM=; b=KdB57e0Pp97tnFCNxfgm32NQnKOAyGWV/dGo/r9+3ty1punhwJ5ht/DdBmC9H8sAti BwpUvvwlaQqJZCP26S9uspR0FHG/k52+vMpS/7MBcALHE6Ng74OJsfX4k9Fq7z9y+jV2 jVorMbdC7BMS2rarZANCkP1oAd93IIxSYtnQlV4g/JKrBHvW4OQjvWFQp/k5a7PoMVnr ZQYSb+anMQuthUzjm8F9SiNy37Nko7Ci3UE1ljX1bQujMNwk/u8ivMAc0w6t0OGJYSus SQb7bQqQzl3/b7JlbCtxmbZiwlY+l+7AK+kWgvkYRxKAr0jPGIV7FUEYtLkfxqZvDJSa clbQ==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769514872; x=1770119672; 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=6ljhRXbB4Fwzv3uMDuN+yFNTuGsar0eJPdydHer4EWI=; b=KXLK0E8aN9GSzJ1/AtjJZQmZlkXKiJ/0wkrFT3PbX9qOekPP8zMN0MT4Dz++ccW/j8 c4hzx/S/KBaLp574S9TX/HhkqngbIMuHIyZfTAJ4JuqfmFl7P0jOLdtBwO764QQhehEx SsLRZz+260jGX+9ZhnsLtQ1SL76JPFb69Xl8v7KXSvQf2PrDxhu3L+Nq64Z5ymdz5mcU 7cygj2r55zPyeaks5RiN2JHIHxzf/BtBiSdT08TT8C03JQJg0iM6th8JYEJRnbBt7GNx zApTPhwX7bglWMH7H9x9pOLkm4Mi0QXhUWzRbMm0Wsjt6TGq6kBoGvE0AS9wqhdsh7S1 aczw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769514872; x=1770119672; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6ljhRXbB4Fwzv3uMDuN+yFNTuGsar0eJPdydHer4EWI=; b=Cx05jjH2QIY8UCd/E06veddfj0xj+Ghwyao3llmpij+hrLXCfjHS8rIbuTYiJNeocn H0kSK73RBYpUNMGk/9tSO07K7GZuB0gPQV4hoDFLeuzNFjRQ0Nk3maSu5xaP9t15JtUY fstPyUDK9gBGjKRXLlcsgQon6NbF8SAPObwG/LuA5SmmnhSR9GnCmmPE5+UmJ+Re1MX5 1UtiGD5lo7vvV78FHBxeFnNigPt1OOcsCj/BrlUbFpsEpHFIDIXcAhMNRuJEfv5qrcHy WJHBO2gXVzy6u+wt8QHv55bIrwUAIg07GBoBpKWVWEaRnB7SJeZi26LhHQ18gAeziD8R q/zQ== X-Gm-Message-State: AOJu0Yz8rDlLz00d0G67eJCWjVXVsOvpX2PEjlh3SFjGD1kJPQJra6Vf 2gj6IWPlV9aoMhQ7I+cLyh6dcsomFrRkYA8MyhMI5ZJnU5lxXeJ7TVcxMon7vGowu+7uW49Oxk/ vU+gN37SZr78LN/NKaR621W8E+RxSbJI= X-Gm-Gg: AZuq6aIIWDg9b26EqU3AxtRIQ+6sUBk8x/iY2DEjBvrdzPYizU5nPsey4AfaWtGP+F0 BlEWLgLjYufFNxDgEDuGhp5k3AxesEn7PrpcuOQCiP42WVStGUIs11+KTX02y3jX4roAmOWYt/W nEf0Uc5I2lYGSuErF2DrlTVJN2bNFxRrDyZBMURxWmXRjlNVrH4q2L4C3ToeMpUVPoBsmxEkM8u Mg9D0y197VEJLRGwMooljMFIiMkpgNwiDQRySQQmd0EW5xoHjpoZ+4E/0XwkLE31YZJpnXrCQm/ 0ug4o2hhhPIdY1q+UUbAn9lYkot8WlMikcNg0FbZIfJXnw7MB1mgWje9K8xwMPznlpdqXAkDBku HjXy+IQ== X-Received: by 2002:ac2:5bcb:0:b0:59e:2a5:e252 with SMTP id 2adb3069b0e04-59e0413c871mr502641e87.23.1769514872055; Tue, 27 Jan 2026 03:54:32 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 27 Jan 2026 12:54:05 +0100 X-Gm-Features: AZwV_Qh-3unsBLTPSqUTxfv3Kd-WVvgzWXbAUF3ZjAPN55QzsTL16LI_GFBD1q0 Message-ID: Subject: Re: [PHP-DEV] [RFC] Deprecate Fuzzy Type Casts and Allow Stringable in Strict Mode To: Alexandre Daubois Cc: PHP internals list Content-Type: multipart/alternative; boundary="0000000000005fac5a06495d490f" From: kjarli@gmail.com (Lynn) --0000000000005fac5a06495d490f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 23, 2026 at 3:17=E2=80=AFPM Alexandre Daubois < alex.daubois+php@gmail.com> 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. > > > Does this behavior als affect parameters being passed in a non-strict > fashion? Because then I don't see a realistic migration path within the > next decade for this application. > > This behavior already exists and forbids such casts, see > https://3v4l.org/WQJPv#vnull. > 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 unknown 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, 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, becomes (int) 123 int $var =3D (int) '123test'; // becomes (int) 123, existing behavior ``` 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. Bonus: ```php int|null $var =3D '123test'; // could result in `null` instead of throwing, similar to the Enum tryFrom. // could enable 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 taken as base for custom cast functions, but that's probably a whole different can of worms. --0000000000005fac5a06495d490f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Jan 23,= 2026 at 3:17=E2=80=AFPM Alexandre Daubois <alex.daubois+php@gmail.com> wrote:
I understand the concern abou= t 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.

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

This behavior already exists and forbids such casts, see
https://3v4l.org/WQJPv#vnull.

Th= anks for your reply!=C2=A0

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 unknown break. I do not have voting power, so all I can g= ive is my opinion.

As an alternative, what about t= his? It could be the best of both worlds where the new behavior is explicit= :
```php
$var =3D (int) '123test'; // still wor= ks, nothing changes, becomes an `(int) 123`
int $var =3D '123= test'; // follows the proposed rules, errors because it's not a val= ue that's a valid integer
int $var =3D '123'; // work= s because it's a valid integer format, becomes (int) 123
int = $var =3D (int) '123test'; // becomes (int) 123, existing behavior
```=C2=A0
This way nothing breaks and the casting remain= s what it is, but we can still enforce correct types. I know the 3rd line m= ight be controversial, but it makes it an opt-in instead of opt-out feature= and errors can be thrown as of day 1.

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

=
// could enable
MyEnum $foo =3D '123test';
MyEn= um|null $bar =3D '123test';

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

`from` and `= tryFrom` could be taken as base for custom cast functions, but that's p= robably a whole different can of worms.
--0000000000005fac5a06495d490f--