summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2019-11-20 02:14:20 +0100
committerMáté Kocsis <kocsismate@woohoolabs.com>2019-12-05 08:30:47 +0100
commit04deb532f033db5c1707ca4b1842f718cc841337 (patch)
treec084e773e6ef673062e4dcfdb984d0e2e2dc4bf5
parent616ec2dd98a8f99090e7382c80394e2dd5b2e869 (diff)
downloadphp-git-04deb532f033db5c1707ca4b1842f718cc841337.tar.gz
Promote warning to exception in log() function
-rwxr-xr-xext/standard/basic_functions.stub.php2
-rwxr-xr-xext/standard/basic_functions_arginfo.h2
-rw-r--r--ext/standard/math.c6
-rw-r--r--ext/standard/tests/math/log_error.phpt10
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--
<?php
-log(36, -4);
+try {
+ log(36, -4);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
?>
---EXPECTF--
-Warning: log(): base must be greater than 0 in %s on line %d
+--EXPECT--
+Base must be greater than 0