Hello Markus, Sunday, May 21, 2006, 12:54:37 PM, you wrote:
> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > [sorry for sending twice, Marcus, gone through wrong list email] > Hi, > I expected this to be bogusfied. The thing is ... if you put a normal > string for a %d it just works. Now that people learn about __toString() > I think it's not clear why %d doesn't work for an object, because also > (string)$obj, as Marcus pointed out, works. > Is it totally off-side to support objects where also integer would be > expected, were usually a string instead of an integer also works? > Either by introducing __toInt() [ok, I think I better not suggest this] > or at least also call __toString() for integers [which may be actually > ever worse idea] or e.g. call __toInt() if available, if not > __toString() and if not available -> standard behaviour. > Or should I better just not have sent this email? Probbaly, this is most likely causing the next useless/senseless thread with tons of mail replies hitting reply before thinking. Well, we could convert the output of __toString() to an integer but generally that is not the way the engine is designed and most likely causing a lot of unwanted sideeffects. The correct solution would be to add something that allows to hook into engine' object get handler or allow to specify which type the cast handler is supposed to return. Both could be accomplished by an interface and a maybe a bit of stuff to make this work. That said we have enough time for PHP 6.0 and should not do anything in 5.x. best regards marcus > PHP Bug Database wrote: >> ID: 37538 >> Updated by: [EMAIL PROTECTED] >> Reported By: [EMAIL PROTECTED] >> -Status: Open >> +Status: Bogus >> Bug Type: Strings related >> -Operating System: Linux >> +Operating System: * >> -PHP Version: 5CVS-2006-05-21 (CVS) >> +PHP Version: * >> New Comment: >> >> Thank you for taking the time to write to us, but this is not >> a bug. Please double-check the documentation available at >> http://www.php.net/manual/ and the instructions on how to report >> a bug at http://bugs.php.net/how-to-report.php >> >> %d is an integer conversion "(int)$obj" as apposed to a string >> conversion that is served by __toString(). >> >> >> Previous Comments: >> ------------------------------------------------------------------------ >> >> [2006-05-21 05:40:36] [EMAIL PROTECTED] >> >> 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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php