Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117537 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79263 invoked from network); 16 Apr 2022 09:44:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Apr 2022 09:44:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2EFB71804D0 for ; Sat, 16 Apr 2022 04:17:21 -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,FREEMAIL_FROM, 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-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 ; Sat, 16 Apr 2022 04:17:20 -0700 (PDT) Received: by mail-wr1-f54.google.com with SMTP id t1so13302304wra.4 for ; Sat, 16 Apr 2022 04:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:subject:user-agent:in-reply-to:references:message-id :mime-version:content-transfer-encoding; bh=XCPbWPqHEq+t2bAp76c96du4uNNyoalvPZPrFNA6/jI=; b=Hzx+OdxyGjsYrFVZLvgh1C1MxcM1x3tgXPVCqMRUbEsNl796dIcsUWwT/ZUjGqVPVm PQsRGNb8tEmzcWh7rzQeJ4/heGQTwQlRGysvnIbVCxxDjKtmUyBmGukmOkdXjvEqYnDI IkXjr5vTopb4TLZGmDDEJLldHhAgj4vjgU6jSKcLFmymEWUWJLxqbxxhKZhSPUwoysRW sgHTfBhDEQEkxyCDwSFo9HA/b7UIUPfhuw9Qp7nrMr8CPcJv7AmjZqdCflnU7+miKu5o M7zDc+WJIyZ9KcJ/QmnYlRVJeVIs8GA3qdq7vB6kSHEW98GbgXttRPbulfMgI7I7yGQG WVow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:user-agent:in-reply-to :references:message-id:mime-version:content-transfer-encoding; bh=XCPbWPqHEq+t2bAp76c96du4uNNyoalvPZPrFNA6/jI=; b=zULq+6v+efdNfgc4j4xGiE1Cf2dRph70fqHf6fS8jRvAfo+rIn6+zBk8jlBbzam/43 M3kduEPHitbM/YliSov2DqVhc4DLpikl89ejroIsPOWvOcryu3QUSJpXCzsJTDfTBvmA Mua8A3lsSwz9ogbKRDDbfdTUs8aitgY4827bEn/QFtdFdTA2weWXQ55O1YuscgGRGc3k 7ZLQSDgGrOLIgQUcCgqOOMn3vnniViiSxADj2kDKQ10EdcoAcntnQq8cKkStZ7Mr3cJv EYvqqIKoHhCB1S2FdSQKcj82J84vrFZzDO4QEaTtXNMWjQmBXQnY5ry0/XpgrzskVs9Q MsMA== X-Gm-Message-State: AOAM532xg/Xql5mm6lp4WxEKv8XmNI+ACFigR1ynfx1gxe6a8zqLa0tT qiTA0cT4RT0ohBjkk4j1cxvqWJbd+y0= X-Google-Smtp-Source: ABdhPJzWO8dMq7ucQC/P/pVtVg8qUdbdoioAfMttkY/BWtqSNpHMXKYtuvPFQO5f/TBevw8jbktuVw== X-Received: by 2002:a05:6000:111:b0:207:ac77:3d07 with SMTP id o17-20020a056000011100b00207ac773d07mr2292310wrx.136.1650107839538; Sat, 16 Apr 2022 04:17:19 -0700 (PDT) Received: from [127.0.0.1] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.gmail.com with ESMTPSA id w8-20020a1cf608000000b0038c8fdc93d6sm10638838wmc.28.2022.04.16.04.17.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Apr 2022 04:17:18 -0700 (PDT) Date: Sat, 16 Apr 2022 12:17:17 +0100 To: internals@lists.php.net User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <42D0A480-F262-4F72-9C4D-887762A8D800@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] NULL Coercion Consistency From: rowan.collins@gmail.com (Rowan Tommins) On 8 April 2022 18:34:52 BST, Craig Francis = wrote: >I've written a new draft RFC to address the NULL coercion problems: > >https://wiki=2Ephp=2Enet/rfc/null_coercion_consistency I'm sympathetic to the general problem you're trying to solve, but I'm not= convinced by the argument that this is about consistency, because user def= ined functions have been consistently rejecting null for non-nullable param= eters since PHP 7=2E0, and even before that for arrays and objects=2E Consi= stency is a good argument for small changes that eliminate unusual edge cas= es, but I think far-reaching changes should be able to stand on their own m= erits - regardless of whether it's consistent, do we want the language to w= ork this way? To me, the main defence of type coercion is that PHP operates in a world f= ull of strings - URLs are strings, HTTP requests are strings, and a lot of = API responses are strings - so making it easy to work with strings like '42= ' as numbers makes a lot of sense=2E It's not clear to me that this extends= to null=2E I think a large part of the problem here is that null can mean many differ= ent things in different contexts - "unknown", "not provided", "invalid inpu= t", "default", "not applicable", etc=2E These differences are subtle, but lead to different expectations of behavi= our: - Treat null as a specific case with its own meaning, distinct from any ot= her valid value=2E This is what explicitly nullable parameters and union ty= pes allow=2E - Treat null the same as any other out of range value, and raise an error= =2E This is what happens in user-defined functions in PHP, and in built-in = functions expecting non-scalar arguments=2E Compare also out of range actio= ns like division by zero=2E - Treat null as a special state that propagates through expressions, becau= se any operation with an unknown input has an unknown output=2E This is the= approach to null taken by SQL, and by IEEE floating point with NaN=2E It i= s also the basis of the ?-> operator, and of things like Optional=2Emap in = Swift=2E - Treat null as a generic default value which can be filled in implicitly = based on requirements=2E This is the interpretation currently taken by inte= rnal functions for scalar arguments, and what you are proposing to make sta= ndard=2E It is also, as you point out, the way PHP treats null in some othe= r contexts, such as many operators=2E Interestingly, one of your examples mentions filter_input, which takes the= "propagate" approach, and htmlspecialchars, which doesn't=2E It would ofte= n be more useful to retain the information that a value is null than to hav= e it silently converted to an empty string as a side-effect of some other o= peration=2E=20 Perhaps it would be useful to have some function-call equivalent of the ?-= > operator=2E I'm not sure what this would look like for normal function ca= lls, but it would be easy to add if we had a pipe operator, e=2Eg=2E: If this was equivalent to htmlspecialchars($foo) $foo |> htmlspecialchars(=2E=2E=2E) Then this could be equivalent to ($foo =3D=3D=3D null ? null : htmlspecial= chars($foo)) $foo ?|> htmlspecialchars(=2E=2E=2E) I'm not set against this RFC, but I'm not quite convinced by the case it m= akes, and think there may still be other options to explore=2E Regards, --=20 Rowan Tommins [IMSoP]