]> granicus.if.org Git - php/commitdiff
Expect number argument in round()
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Oct 2019 11:49:42 +0000 (12:49 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Oct 2019 11:50:29 +0000 (12:50 +0100)
ext/standard/math.c
ext/standard/tests/math/round_variation1.phpt

index c810c432f3a9e904b7b16955867d39be89714bcf..200c662dcafc828e3892903dd40c77d69669fd58 100644 (file)
@@ -281,7 +281,7 @@ static double php_expm1(double x)
 }
 /* }}}*/
 
-/* {{{ proto int|float abs(int number)
+/* {{{ proto int|float abs(int|float number)
    Return the absolute value of the number */
 PHP_FUNCTION(abs)
 {
@@ -345,7 +345,7 @@ PHP_FUNCTION(floor)
 }
 /* }}} */
 
-/* {{{ proto float|false round(float number [, int precision [, int mode]])
+/* {{{ proto float round(float number [, int precision [, int mode]])
    Returns the number rounded to specified precision */
 PHP_FUNCTION(round)
 {
@@ -356,7 +356,7 @@ PHP_FUNCTION(round)
        double return_val;
 
        ZEND_PARSE_PARAMETERS_START(1, 3)
-               Z_PARAM_ZVAL(value)
+               Z_PARAM_NUMBER(value)
                Z_PARAM_OPTIONAL
                Z_PARAM_LONG(precision)
                Z_PARAM_LONG(mode)
@@ -373,7 +373,6 @@ PHP_FUNCTION(round)
                places = precision;
 #endif
        }
-       convert_scalar_to_number_ex(value);
 
        switch (Z_TYPE_P(value)) {
                case IS_LONG:
@@ -389,9 +388,7 @@ PHP_FUNCTION(round)
                        RETURN_DOUBLE(return_val);
                        break;
 
-               default:
-                       RETURN_FALSE;
-                       break;
+               EMPTY_SWITCH_DEFAULT_CASE()
        }
 }
 /* }}} */
index 454a9129f4be58eb2b317dc6b35c563ea3d5ab66..774532f103756c6e74dd0f9ff47e14d8bb38fd6a 100644 (file)
@@ -81,14 +81,18 @@ $inputs = array(
 // loop through each element of $inputs to check the behaviour of round()
 $iterator = 1;
 foreach($inputs as $input) {
-       echo "\n-- Iteration $iterator --\n";
-       var_dump(round($input, 14));
-       $iterator++;
+    echo "\n-- Iteration $iterator --\n";
+    try {
+        var_dump(round($input, 14));
+    } catch (TypeError $e) {
+        echo $e->getMessage(), "\n";
+    }
+    $iterator++;
 };
 fclose($fp);
 ?>
 ===Done===
---EXPECTF--
+--EXPECT--
 *** Testing round() : usage variations ***
 
 -- Iteration 1 --
@@ -140,27 +144,25 @@ float(1)
 float(0)
 
 -- Iteration 17 --
-float(0)
+round() expects parameter 1 to be int or float, string given
 
 -- Iteration 18 --
-float(0)
+round() expects parameter 1 to be int or float, string given
 
 -- Iteration 19 --
-bool(false)
+round() expects parameter 1 to be int or float, array given
 
 -- Iteration 20 --
-float(0)
+round() expects parameter 1 to be int or float, string given
 
 -- Iteration 21 --
-float(0)
+round() expects parameter 1 to be int or float, string given
 
 -- Iteration 22 --
-float(0)
+round() expects parameter 1 to be int or float, string given
 
 -- Iteration 23 --
-
-Notice: Object of class classA could not be converted to number in %s on line %d
-float(1)
+round() expects parameter 1 to be int or float, object given
 
 -- Iteration 24 --
 float(0)
@@ -169,5 +171,5 @@ float(0)
 float(0)
 
 -- Iteration 26 --
-float(%f)
+round() expects parameter 1 to be int or float, resource given
 ===Done===