diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index 4b8c7c5f187..39228ba7ce0 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -537,15 +537,19 @@ PHP_FUNCTION(bccomp) Sets default scale parameter for all bc math functions */ PHP_FUNCTION(bcscale) { - long new_scale; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_scale) == FAILURE) { + long old_scale, new_scale; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &new_scale) == FAILURE) { return; } - BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale; + old_scale = BCG(bc_precision); - RETURN_TRUE; + if (ZEND_NUM_ARGS() == 1) { + BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale; + } + + RETURN_LONG(old_scale); } /* }}} */ diff --git a/ext/bcmath/tests/bcscale_variation003.phpt b/ext/bcmath/tests/bcscale_variation003.phpt new file mode 100644 index 00000000000..b1c541644c6 --- /dev/null +++ b/ext/bcmath/tests/bcscale_variation003.phpt @@ -0,0 +1,18 @@ +--TEST-- +bcscale() return value +--SKIPIF-- + +--INI-- +bcmath.scale=0 +--FILE-- + +--EXPECT-- +int(0) +int(1) +int(4) +int(4)