ID: 29286 Comment by: sven dot siwek at cvk dot de Reported By: michael at fishnet dot us Status: Open Bug Type: Output Control PHP Version: 4.3.8 New Comment:
My English is rather bad, please be leninent with me. If have following strange behaviour: Content-type: text/html^M X-Powered-By: PHP/4.3.8^M ^M 0000000000.00 0000023.20 Please use cut and paste and see for yourself: <? $sfp=" %010.2f \n"; $schr=sprintf($sfp,'0.00'); $schr1=sprintf($sfp,'23.20'); echo $schr; echo $schr1; ?> It would be very nice to fix that as soon as possible. Thank you Previous Comments: ------------------------------------------------------------------------ [2004-07-20 20:35:36] michael at fishnet dot us Description: ------------ The formatting of printf and sprint "%f" changed from 4.3.6 to 4.3.8. The change appears to have actually been released in 4.3.7, perhaps indicated by the Changelog line "Fixed problems with *printf() functions and '%f' formatting. (Marcus)". Where php has for years taken the format "%4.3f" as 4 places to the left of the decimal and 3 to the right of the decimal, it now reads it as "total width of 4 places, including the decimal point and 3 places to the right". Running the code sample provided between 4.3.6 and 4.3.8 will illustrate the problem. We use php to generate fixed width column files for an old database import system; we found to our surprise this morning that the nightly run did not work. The change broke significant operational code that has been in place for years. Warnings should have been blazened in red letters across the release that existing code could well break. Burying this in a cryptic one liner in the Changelog shows little forethought or consideration for those whose code suddenly will not work correctly, with no real warning at all. This probably will not be accepted as a bug. It seems to be an alignment of php with other language formatting systems, at least perl and C, and I understand that. I don't disagree with the philosophy of the change, but I strongly disagree with the way it was done. Though arguably with less impact, the number format change is comparable to the register_globals change. Putting the change into a security release worsened the impact, as one then has a choice to either stay with the security problems or find a fix unknown quantities of code. When a foundational behavior of php is being changed in the future, please document it profusely. Thank you. Reproduce code: --------------- <?php print "12345678901234567890123456789\n"; printf("%5.2f %8.2f\n",3.4,89); ?> Compare the output between 4.3.8 and 4.3.6. Expected result: ---------------- 4.3.6 output: 12345678901234567890123456789 3.40 89.00 Actual result: -------------- 4.3.8 output: 12345678901234567890123456789 3.40 89.00 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29286&edit=1