Re: NULL Coercion Consistency
| From: | Rowan Tommins | Date: | Tue, 26 Apr 2022 20:11:10 +0000 |
| Subject: | Re: NULL Coercion Consistency | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117631@lists.php.net to get a copy of this message | ||
On 26/04/2022 17:36, Guilliam Xavier wrote:
This is actually a really pertinent example: you might expect mt_rand(null, null) to give the same behaviour as mt_rand(), but actually it will always return 0, because it silently coerces to mt_rand(0, 0). That's exactly the kind of unexpected behaviour type checking aims to protect against. There used to be a lot more functions with pseudo-defaults like this, but a lot were made to accept null in PHP 8.0. e.g. mb_convert_encoding('foo', 'ASCII', null) now acts like mb_convert_encoding('foo', 'ASCII') and looks up a run-time default; but in previous versions it acted as mb_convert_encoding('foo', 'ASCII', '') which is not a valid call. Regards, -- Rowan Tommins [IMSoP]function mt_rand(int $min = UNKNOWN, int $max = UNKNOWN): int {}documented with two signatures at https://www.php.net/manual/en/function.mt-rand.phpmt_rand(): int mt_rand(int $min, int $max): int