diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9e626df950..5425ad184a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4] + php: [7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5] steps: - name: Generate french locale. @@ -46,7 +46,7 @@ jobs: run: composer self-update - name: Install dependencies with composer. - run: composer update $DEFAULT_COMPOSER_FLAGS + run: composer update $DEFAULT_COMPOSER_FLAGS ${{ matrix.php == 8.5 && '--ignore-platform-reqs' || '' }} - name: Run tests with PHPUnit. run: vendor/bin/phpunit ${{ env.PHPUNIT_COMMAND }} diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 3435d9a60a..bf2d841413 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -12,7 +12,7 @@ Yii Framework 2 Change Log - Bug #20453: Fix PHPStan/Psalm types in `yii\web\View` (max-s-lab) - Enh #20461: Add PHPStan/Psalm annotations for `yii\filters\auth\AuthInterface` (max-s-lab) - Bug #20459: Fix return type in `RequestParserInterface::parse` (max-s-lab) - +- Bug #20475: Fix `Formatter` class `asScientific()` method for PHP `8.5` `sprintf` precision change (`6` to `0`) (terabytesoftw) 2.0.53 June 27, 2025 -------------------- diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index 35deac4c6f..2a7066c9db 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -1261,10 +1261,12 @@ class Formatter extends Component if ($value === null) { return $this->nullDisplay; } + $value = $this->normalizeNumericValue($value); if ($this->_intlLoaded) { $f = $this->createNumberFormatter(NumberFormatter::SCIENTIFIC, $decimals, $options, $textOptions); + if (($result = $f->format($value)) === false) { throw new InvalidArgumentException('Formatting scientific number value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage()); } @@ -1276,7 +1278,12 @@ class Formatter extends Component return sprintf("%.{$decimals}E", $value); } - return sprintf('%.E', $value); + // PHP 8.5+ changed sprintf('%.E') behavior: empty precision now defaults to '0' instead of '6' + // Specify explicit precision to maintain backward compatibility + // @link https://github.com/php/php-src/commit/5ed8b2be5533fbd4db95d9724d268eb9c9741f14 + $format = PHP_VERSION_ID >= 80500 ? '%.6E' : '%.E'; + + return sprintf($format, $value); } /**