From 04deb532f033db5c1707ca4b1842f718cc841337 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 20 Nov 2019 02:14:20 +0100 Subject: [PATCH] Promote warning to exception in log() function --- ext/standard/basic_functions.stub.php | 2 +- ext/standard/basic_functions_arginfo.h | 2 +- ext/standard/math.c | 6 +++--- ext/standard/tests/math/log_error.phpt | 10 +++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 758eab341c..759d4f0429 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -911,7 +911,7 @@ function pow($base, $exp) {} function exp(float $number): float {} -function log(float $number, float $base = M_E): float|false {} +function log(float $number, float $base = M_E): float {} function log10(float $number): float {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 394d6f657c..19e714b1d7 100755 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1386,7 +1386,7 @@ ZEND_END_ARG_INFO() #define arginfo_exp arginfo_ceil -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_log, 0, 1, MAY_BE_DOUBLE|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_log, 0, 1, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, number, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, base, IS_DOUBLE, 0) ZEND_END_ARG_INFO() diff --git a/ext/standard/math.c b/ext/standard/math.c index 0eec3b4759..53994af3bb 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -596,7 +596,7 @@ PHP_FUNCTION(log1p) } /* }}} */ -/* {{{ proto float|false log(float number, [float base]) +/* {{{ proto float log(float number, [float base]) Returns the natural logarithm of the number, or the base log if base is specified */ PHP_FUNCTION(log) { @@ -625,8 +625,8 @@ PHP_FUNCTION(log) } if (base <= 0.0) { - php_error_docref(NULL, E_WARNING, "base must be greater than 0"); - RETURN_FALSE; + zend_value_error("Base must be greater than 0"); + return; } RETURN_DOUBLE(log(num) / log(base)); diff --git a/ext/standard/tests/math/log_error.phpt b/ext/standard/tests/math/log_error.phpt index 7c305a4cba..b49ccacf6d 100644 --- a/ext/standard/tests/math/log_error.phpt +++ b/ext/standard/tests/math/log_error.phpt @@ -4,7 +4,11 @@ Test log() - wrong params test log() precision=14 --FILE-- getMessage() . "\n"; +} ?> ---EXPECTF-- -Warning: log(): base must be greater than 0 in %s on line %d +--EXPECT-- +Base must be greater than 0 -- 2.50.1