On 26/04/2022 17:36, Guilliam Xavier wrote:
     function mt_rand(int $min = UNKNOWN, int $max = UNKNOWN): int {}

documented with two signatures at
https://www.php.net/manual/en/function.mt-rand.php

     mt_rand(): int
     mt_rand(int $min, int $max): int


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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to