From:             michael at fishnet dot us
Operating system: 
PHP version:      4.3.8
PHP Bug Type:     Output Control
Bug description:  printf/sprintf floating point output change

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 bug report at http://bugs.php.net/?id=29286&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29286&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29286&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29286&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29286&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29286&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29286&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29286&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29286&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29286&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29286&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29286&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29286&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29286&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29286&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29286&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29286&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29286&r=float

Reply via email to