mirror of
https://github.com/yiisoft/yii2.git
synced 2025-10-29 01:17:13 +08:00
Fix #20475: Fix Formatter class asScientific() method for PHP 8.5 sprintf precision change (6 to 0)
This commit is contained in:
@ -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