diff --git a/NEWS b/NEWS index b3ac9d6b405..8f129d715d8 100644 --- a/NEWS +++ b/NEWS @@ -263,6 +263,8 @@ PHP NEWS (nielsdos) . Fixed exit code handling of sendmail cmd and added warnings. (Jesse Hathaway) + . Fixed bug GH-18897 (printf: empty precision is interpreted as precision 6, + not as precision 0). (nielsdos) - Streams: . Fixed bug GH-16889 (stream_select() timeout useless for pipes on Windows). diff --git a/UPGRADING b/UPGRADING index 1462be95a43..4dca8f2b2c2 100644 --- a/UPGRADING +++ b/UPGRADING @@ -116,6 +116,11 @@ PHP 8.5 UPGRADE NOTES . SplFileObject::fwrite's parameter $length is now nullable. The default value changed from 0 to null. +- Standard: + . Using a printf-family function with a formatter that did not specify the + precision previously incorrectly reset the precision instead of treating + it as a precision of 0. See GH-18897. + ======================================== 2. New Features ======================================== diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index 9a74ae6c877..b2c287c0290 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -591,6 +591,7 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n expprec = 1; } else { precision = 0; + adjusting |= ADJ_PRECISION; } } else { precision = 0; diff --git a/ext/standard/tests/strings/gh18897.phpt b/ext/standard/tests/strings/gh18897.phpt new file mode 100644 index 00000000000..328ea7161e0 --- /dev/null +++ b/ext/standard/tests/strings/gh18897.phpt @@ -0,0 +1,10 @@ +--TEST-- +GH-18897 (printf: empty precision is interpreted as precision 6, not as precision 0) +--FILE-- + +--EXPECT-- +3 +3