Skip to content

Commit 3b48e30

Browse files
committed
[BUGFIX] Fix RoundViewHelper with symfony/polyfill-php84 (#1373)
symfony/polyfill-php84 1.33.0->1.34.0 adds RoundingMode stub [1]. round() in PHP < 8.4 allows int as third argument only, and has been extended with php 8.4 to allow int|RoundingMode. The 'class_exists()' check in RoundViewHelper now suddenly returns true when latest symfony/polyfill-php84 is loaded, and then feeds \RoundingMode enum to round() in php < 8.4, which fails with type error. Yay. The patch switches to a straight version check to trigger the PHP < 8.4 callback chain avoiding RoundingMode enum altogether, to avoid the symfony/polyfill-php84 influence. [1] symfony/polyfill-php84@e4e3f1c
1 parent fc09cff commit 3b48e30

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/ViewHelpers/RoundViewHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function render(): float
9494
{
9595
$value = $this->arguments['value'] ?? $this->renderChildren();
9696

97-
if (class_exists(\RoundingMode::class)) {
97+
if (\PHP_VERSION_ID >= 80400) {
9898
$roundingMode = match ($this->arguments['roundingMode']) {
9999
'HalfAwayFromZero' => \RoundingMode::HalfAwayFromZero,
100100
'HalfTowardsZero' => \RoundingMode::HalfTowardsZero,
@@ -107,6 +107,7 @@ public function render(): float
107107
default => \RoundingMode::HalfAwayFromZero,
108108
};
109109
} else {
110+
// @todo: Remove when PHP < 8.4 is dropped
110111
$roundingMode = match ($this->arguments['roundingMode']) {
111112
'HalfAwayFromZero' => \PHP_ROUND_HALF_UP,
112113
'HalfTowardsZero' => \PHP_ROUND_HALF_DOWN,

0 commit comments

Comments
 (0)