File tree 4 files changed +27
-0
lines changed
4 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -15,5 +15,6 @@ Standard:
15
15
. Implement GH-12188 (Indication for the int size in phpinfo()). (timwolla)
16
16
. Partly fix GH-12143 (Incorrect round() result for 0.49999999999999994).
17
17
(timwolla)
18
+ . Fix GH-12252 (round(): Validate the rounding mode). (timwolla)
18
19
19
20
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ PHP 8.4 UPGRADE NOTES
58
58
would have resulted in 1.0 instead of the correct result 0.0. Additional
59
59
inputs might also be affected and result in different outputs compared to
60
60
earlier PHP versions.
61
+ . round() now validates the value of the $mode parameter and throws a ValueError
62
+ for invalid modes. Previously invalid modes would have been interpreted as
63
+ PHP_ROUND_HALF_UP.
61
64
62
65
========================================
63
66
6. New Functions
Original file line number Diff line number Diff line change @@ -335,6 +335,17 @@ PHP_FUNCTION(round)
335
335
}
336
336
}
337
337
338
+ switch (mode ) {
339
+ case PHP_ROUND_HALF_UP :
340
+ case PHP_ROUND_HALF_DOWN :
341
+ case PHP_ROUND_HALF_EVEN :
342
+ case PHP_ROUND_HALF_ODD :
343
+ break ;
344
+ default :
345
+ zend_argument_value_error (3 , "must be a valid rounding mode (PHP_ROUND_*)" );
346
+ RETURN_THROWS ();
347
+ }
348
+
338
349
switch (Z_TYPE_P (value )) {
339
350
case IS_LONG :
340
351
/* Simple case - long that doesn't need to be rounded. */
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ round() rejects invalid rounding modes.
3
+ --FILE--
4
+ <?php
5
+ try {
6
+ var_dump (round (1.5 , mode: 1234 ));
7
+ } catch (ValueError $ e ) {
8
+ echo $ e ->getMessage (), PHP_EOL ;
9
+ }
10
+ ?>
11
+ --EXPECT--
12
+ round(): Argument #3 ($mode) must be a valid rounding mode (PHP_ROUND_*)
You can’t perform that action at this time.
0 commit comments