php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29286 printf/sprintf floating point output change
Submitted: 2004-07-20 20:35 UTC Modified: 2004-08-02 11:39 UTC
From: michael at fishnet dot us Assigned:
Status: Closed Package: Output Control
PHP Version: 4.3.8 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michael at fishnet dot us
New email:
PHP Version: OS:

 

 [2004-07-20 20:35 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-26 16:02 UTC] sven dot siwek at cvk dot de
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
 [2004-08-02 11:39 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

This is already fixed in CVS.
 [2004-08-09 17:23 UTC] mitsu at ministryofthought dot com
I completely agree. I upgraded to 4.3.8 as part of a security patch and my code started to silently break, causing major problems for my client. Very, very bad that this was not a big warning to PHP developers --- and it should be posted prominently on the home page.
 [2004-08-09 17:26 UTC] mitsu at ministryofthought dot com
Okay, I see this has been fixed, I posted the above before seeing the last comment on this bug.
 [2004-08-16 11:35 UTC] markvds at elegia dot nl
It's still not clear to me what has been fixed. Has the old behaviour been restored, or has only the bug from sven [26 jul] been fixed?
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 12:03:36 2021 UTC