|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-05-21 09:23 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 21:00:02 2025 UTC |
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