From: Nikita Popov Date: Wed, 30 Oct 2019 09:36:42 +0000 (+0100) Subject: Promote mt_rand() min/max warning to ValueError X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=becda2e0418d4efb55fca40b1170ca67cfbdb4e0;p=php Promote mt_rand() min/max warning to ValueError --- diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 8322a63fc0..8e0a2cde6b 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -953,8 +953,7 @@ function quoted_printable_encode(string $str): string {} function mt_srand(int $seed = 0, int $mode = MT_RAND_MT19937): void {} -/** @return int|false */ -function mt_rand(int $min = 0, int $max = PHP_INT_MAX) {} +function mt_rand(int $min = 0, int $max = PHP_INT_MAX): int {} function mt_getrandmax(): int {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 6f16c42aea..24735d679f 100755 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1241,7 +1241,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mt_srand, 0, 0, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_mt_rand, 0, 0, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mt_rand, 0, 0, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, min, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, max, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/ext/standard/mt_rand.c b/ext/standard/mt_rand.c index d38b9cba8d..9dff7da24c 100644 --- a/ext/standard/mt_rand.c +++ b/ext/standard/mt_rand.c @@ -325,8 +325,8 @@ PHP_FUNCTION(mt_rand) ZEND_PARSE_PARAMETERS_END(); if (UNEXPECTED(max < min)) { - php_error_docref(NULL, E_WARNING, "max(" ZEND_LONG_FMT ") is smaller than min(" ZEND_LONG_FMT ")", max, min); - RETURN_FALSE; + zend_value_error("max (" ZEND_LONG_FMT ") is smaller than min (" ZEND_LONG_FMT ")", max, min); + return; } RETURN_LONG(php_mt_rand_common(min, max)); diff --git a/ext/standard/tests/general_functions/bug46587.phpt b/ext/standard/tests/general_functions/bug46587.phpt index becbde9648..ee59feb444 100644 --- a/ext/standard/tests/general_functions/bug46587.phpt +++ b/ext/standard/tests/general_functions/bug46587.phpt @@ -4,13 +4,15 @@ Bug #46587 (mt_rand() does not check that max is greater than min). getMessage(), "\n"; +} echo "Done.\n"; ?> --EXPECTF-- int(%d) - -Warning: mt_rand(): max(3) is smaller than min(8) in %s on line %d -bool(false) +max (3) is smaller than min (8) Done.