mirror of
https://github.com/yiisoft/yii2.git
synced 2025-10-28 12:34:34 +08:00
Fix #20475: Fix Formatter class asScientific() method for PHP 8.5 sprintf precision change (6 to 0)
This commit is contained in:
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -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 }}
|
||||
|
||||
@ -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
|
||||
--------------------
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user