#37538 [NEW]: toString in sprintf/printf and %d modifier does't work as expected

From: Date: Sun, 21 May 2006 05:40:36 +0000
Subject: #37538 [NEW]: toString in sprintf/printf and %d modifier does't work as expected
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-97420@lists.php.net to get a copy of this message
From: mfischer@php.net Operating system: Linux PHP version: 5CVS-2006-05-21 (CVS) PHP Bug Type: Strings related Bug description: toString in sprintf/printf and %d modifier does't work as expected Description: ------------ The modifier %d doesn't work as one would expect sprintf/printf. When a string is returned, it is always replaced %d with '1' instead of the evaluated number of the __toString() output. Consider this: printf("%s %d", "4", "4"); will output "4 4", however if the parameters are replaced with an object whith magic __toString() which returns "4", %d is not replaced with 4 but with 1. It always returned 1, no matter what __toString() returns. Reproduce code: --------------- class foo { function __toString() { return "4"; } } printf("%s %d\n", new foo, new foo); printf("%s %d\n", "4", "4"); Expected result: ---------------- 4 4 4 4 Actual result: -------------- 4 1 4 4 -- Edit bug report at http://bugs.php.net/?id=37538&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37538&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37538&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37538&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37538&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37538&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37538&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37538&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37538&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37538&r=support Expected behavior: http://bugs.php.net/fix.php?id=37538&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37538&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37538&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37538&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37538&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37538&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37538&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37538&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37538&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37538&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37538&r=mysqlcfg

« previous php.bugs (#97420) next »