#37537 [Ver->Csd]: __toString documentation update

From: Date: Fri, 17 Aug 2007 21:30:56 +0000
Subject: #37537 [Ver->Csd]: __toString documentation update
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969377656@lists.php.net to get a copy of this message
ID: 37537 Updated by: vrana@php.net Reported By: mfischer@php.net -Status: Verified +Status: Closed Bug Type: Documentation problem Operating System: Any PHP Version: 5.2.0 New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "Since PHP 5.2.0, __toString() is called in any string context (e.g. in printf() with %s modifier) but not in other types contexts (e.g. with %d modifier)." Previous Comments: ------------------------------------------------------------------------ [2007-06-20 19:05:15] bjori@php.net See also bug#41750 ------------------------------------------------------------------------ [2006-05-29 12:45:28] mfischer@php.net I don't think it's *that* clear. Consider that when you pass a "string" to %d guess what -> it works, the string is converted to an int. But in case of an object, it does not work this way automatically. If you would write (string)$obj it again would work. I don't consider this as clear as blue sky. :) ------------------------------------------------------------------------ [2006-05-29 11:52:53] bjori@php.net No you shouldn't. IMO it's quite clear that __toString wouldn't be called with %i or %e or anything else than %s. But I guess there is no harm in documenting that too.. ------------------------------------------------------------------------ [2006-05-29 06:01:08] mfischer@php.net I had a small conversation with the autor on internals@ and it is very important, because you gave the printf example, that __toString() will only be called if an stirng modified %s is encountered. If it's %d for integer, __toString() is not called. This may or may not be expected, but it's the current implementation. Should I file another report for it? ------------------------------------------------------------------------ [2006-05-26 12:13:46] bjori@php.net http://php.net/oop5.magic#language.oop5.magic.tostring needs an updated before 5.2.0. #1 Can't throw exceptions anymore #2 Is called 'wherever it's appropriate' (e. printf("__toString: %s", $obj)) If language.exceptions will be updated to note where exceptions can't be thrown it'll need to note lot more then just __toString() ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/37537 -- Edit this bug report at http://bugs.php.net/?id=37537&edit=1

« previous php.doc (#969377656) next »