summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-10-29 12:49:42 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-10-29 12:50:29 +0100
commit8f20b9969fb431cebc329995782631e8b5ecf6c2 (patch)
tree80ab938599cbbdc1dba736122ca23904414b7ab2
parent1d631c18deec5d3c73345740ccc3bf2c30aadd66 (diff)
downloadphp-git-8f20b9969fb431cebc329995782631e8b5ecf6c2.tar.gz
Expect number argument in round()
-rw-r--r--ext/standard/math.c11
-rw-r--r--ext/standard/tests/math/round_variation1.phpt30
2 files changed, 20 insertions, 21 deletions
diff --git a/ext/standard/math.c b/ext/standard/math.c
index c810c432f3..200c662dca 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -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()
}
}
/* }}} */
diff --git a/ext/standard/tests/math/round_variation1.phpt b/ext/standard/tests/math/round_variation1.phpt
index 454a9129f4..774532f103 100644
--- a/ext/standard/tests/math/round_variation1.phpt
+++ b/ext/standard/tests/math/round_variation1.phpt
@@ -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===