Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

round() Mode Validation

The round() function has four modes, defined with four constants. When the third argument is not one of those four constants, PHP used to silently use PHP_ROUND_HALF_UP as default value. In PHP 8.4, a ValueError is thrown.

PHP code

<?php

print $a = round(1.2, 2, 333);

?>

Before

1

After

round(): Argument #3 ($mode) must be a valid rounding mode (PHP_ROUND_*)

PHP version change

This behavior changed in 8.4.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat