From: Nikita Popov Date: Wed, 21 Oct 2020 15:03:54 +0000 (+0200) Subject: Update bcmath.scale when calling bcscale() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac87880addfd22e651b210346178dc1ed851b1dd;p=php Update bcmath.scale when calling bcscale() We should keep the value of bcmath.scale and the internal bc_precision global synchronized. Probably more important than the ability to retrieve bcmath.scale via ini_get(), this also makes sure that the set scale does not leak into the next request, as it currently does. --- diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index f20dda534f..95b820e4c4 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -542,7 +542,11 @@ PHP_FUNCTION(bcscale) RETURN_THROWS(); } - BCG(bc_precision) = (int) new_scale; + zend_string *ini_name = zend_string_init("bcmath.scale", sizeof("bcmath.scale") - 1, 0); + zend_string *new_scale_str = zend_long_to_str(new_scale); + zend_alter_ini_entry(ini_name, new_scale_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(new_scale_str); + zend_string_release(ini_name); } RETURN_LONG(old_scale); diff --git a/ext/bcmath/tests/bcscale_variation003.phpt b/ext/bcmath/tests/bcscale_variation003.phpt index b1c541644c..0812aadab6 100644 --- a/ext/bcmath/tests/bcscale_variation003.phpt +++ b/ext/bcmath/tests/bcscale_variation003.phpt @@ -6,13 +6,21 @@ bcscale() return value bcmath.scale=0 --FILE-- --EXPECT-- int(0) +int(0) +int(1) int(1) int(4) int(4) +int(4) +int(4)