Re: Allowing NULL for some internal functions
| From: | Craig Francis | Date: | Tue, 01 Mar 2022 12:55:22 +0000 |
| Subject: | Re: Allowing NULL for some internal functions | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117177@lists.php.net to get a copy of this message | ||
On Tue, 1 Mar 2022 at 09:48, Mark Randall <marandall@php.net> wrote:
> You see a problem, but rather than trying to fix the underlying cause,
> you're proposing making changes at other layers to accommodate the side
> effects of the original problem.
>
> That is practically the definition of a hack.
>
No, there is an inconsistency which leads to a backwards compatibility
issue, and I'm trying to fix it.
I'm sorry I'm clearly no good at explaining this... maybe I should try
bullet points...
I am not trying undo the intent of the original RFC (constancy is good).
PHP has type coercion when not using
strict_types=1; this is a feature,
one you might not like, but many do.
Coercion works for string/int/float/bool, *and* NULL.
It even has it's own clear paragraphs explaining this in the manual:
"null is always converted to an empty string."
"null is always converted to zero (0)."
"the following values are considered false ... NULL"
Not only does this happen with function parameters, but also non-strict
comparison operators, e.g. ($nullable == '') is true for NULL.
It was only user-defined function parameters with a specified type
(introduced in PHP 7.0) that broke that consistency, and only for NULL,
because the other types continued to be coerced, it was just NULL that was
the oddity.
This is important because NULL is used a lot, as both a distinct value, and
as a convention as the default for parameters (ref setcookie).
And internal functions have always accepted NULL.
As of 8.1, the inconstancy between user-defined vs internal functions was
addressed (good, I dislike consistencies), but the details were barely
discussed (one message, from Craig Duncan):
https://externals.io/message/112327
I'm trying to avoid an upgrade problem for PHP 9.0.
I want to keeping the strict checks in place for those who
use strict_types=1 (so Mark, you would not be affected by this, as I
assume you use strict_types=1 for everything).
And note the complete lack of tools to fix this issue, and how many
instances would need to be changed.
Unless you're planning to force strict_types=1 on everyone (Type Errors
for all, remove all type coercion), this inconstancy does not make any
sense.
Craig