Re: NULL Coercion Consistency
| From: | Craig Francis | Date: | Sat, 09 Apr 2022 09:29:42 +0000 |
| Subject: | Re: NULL Coercion Consistency | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117505@lists.php.net to get a copy of this message | ||
On Fri, 8 Apr 2022 at 19:07, Craig Francis <craig@craigfrancis.co.uk> wrote:
> On Fri, 8 Apr 2022 at 18:54, Mel Dafert <mel@dafert.at> wrote:
>
>> In particular, does this propose changing user-defined functions under
>> strict_types=0 to accept null for scalar types?
>>
>
> With user defined functions, I think it's up for debate (still a draft),
> but I think those NULL's should be coerced to the specified type (as
> documented), where I don't think PHP should be doing type checking under
> strict_types=0.
>
I've updated the RFC to note that user-defined functions don't cause a
backwards compatibility issue; but I have added an example to highlight
the coercion inconstancy:
```php
function user_function(string $s, int $i, float $f, bool $b) {
var_dump($s, $i, $f, $b);
}
user_function('1', '1', '1', '1');
// string(1) "1" / int(1) / float(1) / bool(true)
user_function(2, 2, 2, 2);
// string(1) "2" / int(2) / float(2) / bool(true)
user_function(3.3, 3.3, 3.3, 3.3);
// string(3) "3.3" / int(3) / float(3.3) / bool(true)
user_function(false, false, false, false);
// string(0) "" / int(0) / float(0) / bool(false)
user_function(NULL, NULL, NULL, NULL);
// Uncaught TypeError x4?
```