Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129891 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 EDEEE1A00BC for ; Fri, 23 Jan 2026 14:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769177856; bh=x8ihRqoUs2BMgWHpSDPTniUBpsbvV9XBI5Uj7/yP/aA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eYCd81v5d9Pz/xE+ndFVGrFhnTG6gJDCX9tJm8m0iYJ1Zhy2J60wrfbJtBMkysQiy dyiBDgiWzYGJjT3SldGos1orNNDfFduuRog+4q3SptIYX897cq9Q/oqs/1AaumeZsH GbJG9oBmYodNZf41qEoIdtGr82jXHKh3rOYMAvoBkHZTWDC/Vnrj68SDKJII+1Ngok s8DSLBe8h1SDpdY4UE1XCYFPM6Pt2Ghxg5O2V5YWADWjNokEzEPvRV3/JhAg6V9XVs iXTo5PzWAgkyGtGoO7wHgkUBO8xMHHH6cIxSjLQ3fKCq2vwgegwgRD/Tjia0grrhjp 7CrumCLqikOSA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BBB711804F7 for ; Fri, 23 Jan 2026 14:17:35 +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.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_FROM,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-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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, 23 Jan 2026 14:17:35 +0000 (UTC) Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-6505d141d02so3307793a12.3 for ; Fri, 23 Jan 2026 06:17:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769177849; cv=none; d=google.com; s=arc-20240605; b=RWTvup6qqJjnaSXQ2bhCaF5REMUH2GaJuly+sfd8WGLAM1cOObyqIZJlRMWdIvFgbR WviUJXJfT0+UoZ/ynIRpMRFe2ec9J5bgDTah4p+thHZ8nOWPEYnrrV3Rred/0PRCfJsR ePt+TjKNNsybFYR0W782CSxtv4/7uQNQt/sn0VS7qj9wUonBgcpFymvAvDsHh6MZvT2t uZ8bAXFjU3JRJa36NOgrftjAV4jH3i4cUv2bE8gPpltbqM3D0jRL24GQ7OugQ9hCIyQa cOqZiX29UUWpkBfRbiWGJBxKol+3VFMCu7heCkV4Em8EyGnZSAHCP0ZtG6JgNXoXKUXm kJcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=x8ihRqoUs2BMgWHpSDPTniUBpsbvV9XBI5Uj7/yP/aA=; fh=XHCzPWKSbfW6ooqd1Y4NgUwuaN5NcoRHPdv7NtJX1qg=; b=frdA4UuHRyaPPUhrmbJu9+A/Ys98tXJqQBbzmaB/quIcljKvgNaT7N5ztUB4XLHW6D IWRrmooF1DRnb49TuwQpVHuyvTsLQn5/jEfIM6klC48KREMxcEZwWp8nfc+E/Ahcydo+ +Haf3SYWW0COd5n0CN2YuiscXXVdgNvFfyQ5ZcDS9j5h2vpW29v+Fz+a1BUbxJX83OCp fXTr6V7p2lM+o8ufCoTrrTFcoqnKBO34SYmMEMThZSvl9XZtw2yD5VijNeqKc5ZJUK6Y O4tWeOzNmFj89EfIKpNT2HbBZpz3p6DUzURS1z2Ush8VPoPjQ2qXpdUtJPAygReJ3wVc G2OA==; 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=1769177849; x=1769782649; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=x8ihRqoUs2BMgWHpSDPTniUBpsbvV9XBI5Uj7/yP/aA=; b=lRCEFYwOjt470Nr7SOzlLUkehhp3EC+lQUOgEuw7RiGwxbTdKUMAjujmBdAsSaRsEN JmtlupymD8q+CuglDm8jrMy62IuKy7BAQknhe2Bf0HHNbcPo7bitvHOWKhxXJxI8ZMgc KHNKgXX2oNThmvkcNj283PUQ4OCF00WytVatdIvM4kyCL6/hmiEReow/FmaImicBcm0b DAmahsY7LlSOIDsJRWeqgAIIAxWdbwu2DLdPflf7WSJ7y1glV02GpQbHUouZjcxA+E1Q uP454TlnXAJGnAA4blUjpIvXHeiYZUNwq5mbfL6/DtllX4/b5WED/1KwCuPULeKeo+bL +i0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769177849; x=1769782649; h=content-transfer-encoding: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=x8ihRqoUs2BMgWHpSDPTniUBpsbvV9XBI5Uj7/yP/aA=; b=Gd/sO8Hrt2ke6Xs8oCZEa8U7YjyOhKVFJTnwHRnFjajFnm03ZMjwXDFllv6v5wRmOO e3YkxBh4MOuybG3dn0MrQVOpootfzXYpptqTt/6qPMwCWxdY5HdukicqD8J/5pNrCRUz rEHyKblGlt+tfNFzivqZV2v8QtLOgN8Yc+PQypDh2oAx1yHwENGl7VWOgZefS2n6V5fD iwyqPKILevv4KtB3CiBZT9d2Xct2b8oyaSiS7QhxD6grlQAZ6ISaWEY6Zv07pDws6BgE aer5WcdQE8to+atNp3KIwU4IWtMSLUqIjDsjm04UkKeQA9frgoMwpn5kM1fOGINb1Jsz nxyw== X-Gm-Message-State: AOJu0Yxzt8XdDCNqhOYcAWmddND4Tx8MYCFbeGOiIhw6uaheyJzuhHd0 chH2WCJfULghgPq0srKT6J6Li6p3MrB11jqgIZxhooCBwBaLMqHCAOKP4hZZnCD/Fi0zYrbrkoP ustY3VA9AgE6Xv6T5reyKwqmsswCEs+n5eI6J X-Gm-Gg: AZuq6aLmc0ELrP3nxfXsQurYMjdM6NTyRWWJJ36G9r9LG2bIGj/Vx35/Ejgr+lk+kHm f//KG4nL6rTp5RygQjNpXozzweZXEA6S7Db+VRhMt77MHnXb7t/Yzy/yUmhHFUjcnjuv0TbHd2U +lnkcEBdgVQuSMIPsnV6yqUKjTcFJHnNOCbjx52j/EIjRR5kng3VXeHiISoRPJkGuzdcUPSigyR +NK7T2qViIiCeMMfg0ob6u7qTpoicegSVfX+IJ40RaJq33RDgXJrevtYGgf62agphTej5ykFKIM Ku0BIkkfBz85UA== X-Received: by 2002:a05:6402:3481:b0:658:15c4:6784 with SMTP id 4fb4d7f45d1cf-658487c985emr2112559a12.29.1769177849097; Fri, 23 Jan 2026 06:17:29 -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: Fri, 23 Jan 2026 15:17:17 +0100 X-Gm-Features: AZwV_Qgtrwd0Cd5qSNW4voi-Hq8BI4M_icBNOB5PzRLaSVrx74UZMTqN9CXAZuE Message-ID: Subject: Re: [PHP-DEV] [RFC] Deprecate Fuzzy Type Casts and Allow Stringable in Strict Mode To: Lynn Cc: PHP internals list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: alex.daubois+php@gmail.com (Alexandre Daubois) Hi Lynn, thank you for sharing your thoughts. Le ven. 23 janv. 2026 =C3=A0 12:44, Lynn a =C3=A9crit : > What's the expected behavior of `(int) '001'` and `(int) 1.`? I would exp= ect both to still be valid integers, but I can't tell from this RFC if thos= e scenarios would be affected. The first scenario is common with "ZEROFILL"= database columns, and the latter is a scenario I recently found being used= to get a valid int from user input if considered number-ish and switch bet= ween whole number vs decimal behavior. They will be indeed valid integers. There is no lossy cast here: "001" and "1." are valid integers and expected. > I'm afraid that deprecating and eventually erroring these casts will brea= k a lot of hard to trace legacy code, where a cast "solved" most problems, = or at least did not crash things. I'm talking about values that come from a= utomated import systems, go through dozens of layers of code that haven't b= een touched since php 5.2 or earlier, and eventually end up in a part where= we do a cast. It was also not unthinkable that these casts were used _beca= use_ it truncated the invalid parts, and while we could replace this with a= preg_match to extract the number, I don't particularly feel like going thr= ough nearly 5k int casts in this codebase and figure out if it should chang= e or not. 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 fas= hion? Because then I don't see a realistic migration path within the next d= ecade for this application. This behavior already exists and forbids such casts, see https://3v4l.org/WQJPv#vnull. > On the subject of strings, I'm very afraid this will cause hidden issues.= The Stringable value isn't always the value I want from an object, and wit= h this change my IDE will no longer give an error that it's the wrong type. This is exactly the intended behavior: Stringable *is* an explicit contract informing that an object can be converted to string. Non-strict mode is aligned with that, whereas strict mode misleadingly forbids that. Default mode has better casting rules that strict mode doesn't offer. The whole "non-strict community" uses this rule, making their code simpler by not having to deal with a union type every time. > I foresee people throwing stringable objects into string parameters and s= ilently causing the wrong values to be used. Again, Stringable is an explicit contract to define the appropriate string representation of an object. If this is a problem, the issue lies in the `__toString()` implementation. > This will also silently break values being passed if the __toString imple= mentation changes, which is going to be extremely hard to trace back like w= ith `(string) $object`. If any `__toString()` implementation changes in your object, it will already break everywhere the object is casted to string or used in a string context. This is an API breaking issue, which, to me, feels unrelated to the RFC. > This change also makes reviewing code more difficult as I have to know th= e parameter type, variable type, and what the __toString function does in o= rder to find out if it's correct, or another value had to be passed. With `string|Stringable`, you have to check two types (even if `Stringable` is meant to be an explicit contract). With just `string` that accepts Stringable, it's simpler and more consistent. The code will also be less error-prone. =E2=80=94 Alexandre Daubois