com php-src: Promote mt_rand() min/max warning to ValueError: ext/standard/basic_functions.stub.php ext/standard/basic_functions_arginfo.h
ext/standard/ mt_rand.c ext/standard/tests/general_functions/bug4 6587.phpt

From: Date: Wed, 30 Oct 2019 09:36:42 +0000
Subject: com php-src: Promote mt_rand() min/max warning to ValueError: ext/standard/basic_functions.stub.php ext/standard/basic_functions_arginfo.h
ext/standard/ mt_rand.c ext/standard/tests/general_functions/bug4 6587.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109131@lists.php.net to get a copy of this message
Commit: becda2e0418d4efb55fca40b1170ca67cfbdb4e0 Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 30 Oct 2019 10:36:42 +0100 Parents: ad9ea5abded29402292b52000f22be122ee32059 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=becda2e0418d4efb55fca40b1170ca67cfbdb4e0 Log: Promote mt_rand() min/max warning to ValueError Changed paths: M ext/standard/basic_functions.stub.php M ext/standard/basic_functions_arginfo.h M ext/standard/mt_rand.c M ext/standard/tests/general_functions/bug46587.phpt Diff: diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 8322a63fc03..8e0a2cde6b0 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 6f16c42aea5..24735d679ff 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 d38b9cba8d2..9dff7da24c3 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 becbde96487..ee59feb4445 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). <?php var_dump(mt_rand(3,8)); -var_dump(mt_rand(8,3)); +try { + var_dump(mt_rand(8,3)); +} catch (ValueError $e) { + echo $e->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.

« previous php.cvs (#109131) next »