Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117679 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26494 invoked from network); 6 May 2022 22:53:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 May 2022 22:53:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D916E180053 for ; Fri, 6 May 2022 17:31:25 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 6 May 2022 17:31:25 -0700 (PDT) Received: by mail-wm1-f47.google.com with SMTP id bg25so5430101wmb.4 for ; Fri, 06 May 2022 17:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=bmtf0cqCJCqjZfyjc0Ee3ZsibVgpEpeLTwYKh1TLU6c=; b=DBQe9Cc05LfWu5gL+xxA//672wZd8ETLZuEDglttEiPrcXtuYX4spqH+J/9xoejzK+ 6C3VHoovStiUR6pXeFmL0axa7v0/qzh1IlVtBjN5RrUVbkHzdnt8L8vpXeYXKt8QUiGn AcHWkv4vZaxmVn2WMHTCiP6vN+MeoST51DHck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=bmtf0cqCJCqjZfyjc0Ee3ZsibVgpEpeLTwYKh1TLU6c=; b=6hUiJbu9+k1wghq5c7o8Cge7YaL3bCJSEXsugZW6wB35VhzXhn1vEDiVI7nck5XK7l muDq6OGMYbE68ltx204IZvCD20ku67Kkik09ECPIF+M3PjPyZRBCLJWcg+NAl1aPTnwD upkGoaKPRG0P4/HOBW1SBcYOjy95jQzeu+1vlkvkRoWOL8RQM39DRaDXbvNn8Dtc/6av uzfoIA4m70PzR9+cGUtqvpWtt4miE5SZIrimjms2PC23BgJG86WrfSP+5Qr+6LMFbEcz 30O4aofXHymK0vtcR9F1o1CRFsXtJxUqbcnu9y9JmMlwPQ7HwiAsI698WD4t+iS2i40n rpRA== X-Gm-Message-State: AOAM532bFt7+p0dqo99SOMPt3ui0ONWBTqjH1JrOHqQU8Rlu1a1+Bal9 F/jH3i8T0IYjMOcQja0PlInfG0z7WHsm7g== X-Google-Smtp-Source: ABdhPJxKBRGUj1iRIgOQTch4DT5AriOa5HkSf4oxJzASnVBVUk18zcdCwhO9PPYkZleBho94NqvEng== X-Received: by 2002:a05:600c:3d16:b0:394:4ff0:d818 with SMTP id bh22-20020a05600c3d1600b003944ff0d818mr5562550wmb.5.1651883484087; Fri, 06 May 2022 17:31:24 -0700 (PDT) Received: from smtpclient.apple ([94.173.138.98]) by smtp.gmail.com with ESMTPSA id u8-20020a5d4688000000b0020c5253d8ecsm4584002wrq.56.2022.05.06.17.31.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 May 2022 17:31:23 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) In-Reply-To: <9109f8bb-2582-2578-f702-464f921590e5@telia.com> Date: Sat, 7 May 2022 01:31:20 +0100 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <9109f8bb-2582-2578-f702-464f921590e5@telia.com> To: =?utf-8?Q?Bj=C3=B6rn_Larsson?= X-Mailer: Apple Mail (2.3696.80.82.1.1) Subject: Re: NULL Coercion Consistency From: craig@craigfrancis.co.uk (Craig Francis) On 6 May 2022, at 16:26, Bj=C3=B6rn Larsson = wrote: > Den 2022-04-08 kl. 19:34, skrev Craig Francis: >> Hi, >> I've written a new draft RFC to address the NULL coercion problems: >> https://wiki.php.net/rfc/null_coercion_consistency >> ... >=20 > One code pattern to upgrade your code to PHP 8.1 and 9.0 is to use the > null coalescing operator like rtrim($string ?? '',...). >=20 > If one then has a legacy codebase that works flawlessly I would say = that > this path is the preferred one since it requires a minimum of work. To > dig into your code base and address why the parameter ends up like = null > is probably more cumbersome. OTOH, one doesn't reap the benefits of = the > "Deprecate passing null to non-nullable arguments of internal = functions" > RFC since it requires to much work. >=20 > One could argue that the "Deprecating passing null" RFC is nice, but = has > a flaw when applied for existing code. Applying the null coalescing = code > pattern is an easy way to make your code 8.1 compatible, but not sure = if > it adds value to the application itself. >=20 > Now if this RFC is the best way to improve things if one think this is > something of an issue with the original RFC worth addressing I don't > know. But at least worth having a discussion about! The purist within > me sighs a little when applying the code pattern above... Thanks Bj=C3=B6rn, My main concern is about backwards compatibility. If this RFC fails, I think the only way for existing code to avoid the = issue will be via an automated tool, but for it to do this safely, I = agree with your suggestion, I think it will need to use null coalescing = (or casting via `(string) $var` or `strval($var)`) at the variable = sinks... but the idea of doing that to the ~335 parameters I've listed, = is, well, ugly to say the least... but I'd much rather do that, instead = of having projects stuck on 8.x (where they will inevitably stop = receiving security patches). I would like to know about the future benefits, and this is where my = discussion with Rowan has been interesting (trying to work out the = benefits vs costs)... but, tbh, I'm not really seeing a future benefit = for breaking NULL coercion with internal functions (sorry). I do see = benefits for consistency, and rejecting weird forms of type coercion = (e.g. `htmlspecialchars(array())`), and I've tried to factor these into = my RFC, but considering how NULL and an Empty String can often be seen = as interchangeable (many developers giving no thought to the = difference), I'm not sure how these fatal errors will help. Craig