Skip to content

Commit ac87880

Browse files
committed
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.
1 parent cb6f9a6 commit ac87880

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ext/bcmath/bcmath.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,11 @@ PHP_FUNCTION(bcscale)
542542
RETURN_THROWS();
543543
}
544544

545-
BCG(bc_precision) = (int) new_scale;
545+
zend_string *ini_name = zend_string_init("bcmath.scale", sizeof("bcmath.scale") - 1, 0);
546+
zend_string *new_scale_str = zend_long_to_str(new_scale);
547+
zend_alter_ini_entry(ini_name, new_scale_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
548+
zend_string_release(new_scale_str);
549+
zend_string_release(ini_name);
546550
}
547551

548552
RETURN_LONG(old_scale);

ext/bcmath/tests/bcscale_variation003.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ bcscale() return value
66
bcmath.scale=0
77
--FILE--
88
<?php
9+
var_dump((int) ini_get('bcmath.scale'));
910
var_dump(bcscale(1));
11+
var_dump((int) ini_get('bcmath.scale'));
1012
var_dump(bcscale(4));
13+
var_dump((int) ini_get('bcmath.scale'));
1114
var_dump(bcscale());
15+
var_dump((int) ini_get('bcmath.scale'));
1216
var_dump(bcscale());
1317
?>
1418
--EXPECT--
1519
int(0)
20+
int(0)
21+
int(1)
1622
int(1)
1723
int(4)
1824
int(4)
25+
int(4)
26+
int(4)

0 commit comments

Comments
 (0)