]> granicus.if.org Git - php/commitdiff
Promote warning to exception in log() function
authorMáté Kocsis <kocsismate@woohoolabs.com>
Wed, 20 Nov 2019 01:14:20 +0000 (02:14 +0100)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Thu, 5 Dec 2019 07:30:47 +0000 (08:30 +0100)
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/math.c
ext/standard/tests/math/log_error.phpt

index 758eab341c08bcc2e4336cddc6f8405fe3d71373..759d4f0429a77a08494d7c5b72c234b0191d074f 100755 (executable)
@@ -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 {}
 
index 394d6f657c4ab15a711e85f72d1399ab102cfcf6..19e714b1d7d5bc1d1923d5b208ed61661f7b5671 100755 (executable)
@@ -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()
index 0eec3b4759729dfaf03b166df89aa803b686da93..53994af3bbb9c1aea4bbba32d3177abc326f9741 100644 (file)
@@ -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));
index 7c305a4cba86c593f386aa5233138fe561e68449..b49ccacf6d7000c9a40d9d0befbf265d06a2e3c9 100644 (file)
@@ -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