diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-21 17:03:54 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-21 17:06:48 +0200 |
commit | ac87880addfd22e651b210346178dc1ed851b1dd (patch) | |
tree | 23b6613bd80f0240ad9733ef9821bcd0aeed1a83 | |
parent | cb6f9a65681bedee18fbd994495ddf3ba41367ac (diff) | |
download | php-git-ac87880addfd22e651b210346178dc1ed851b1dd.tar.gz |
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.
-rw-r--r-- | ext/bcmath/bcmath.c | 6 | ||||
-rw-r--r-- | ext/bcmath/tests/bcscale_variation003.phpt | 8 |
2 files changed, 13 insertions, 1 deletions
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-- <?php +var_dump((int) ini_get('bcmath.scale')); var_dump(bcscale(1)); +var_dump((int) ini_get('bcmath.scale')); var_dump(bcscale(4)); +var_dump((int) ini_get('bcmath.scale')); var_dump(bcscale()); +var_dump((int) ini_get('bcmath.scale')); var_dump(bcscale()); ?> --EXPECT-- int(0) +int(0) +int(1) int(1) int(4) int(4) +int(4) +int(4) |