ID: 47781 User updated by: fabien dot meynard at supinfo dot com Reported By: fabien dot meynard at supinfo dot com Status: Bogus Bug Type: Class/Object related Operating System: macos x PHP Version: 5.2.9 New Comment:
I'm sorry but in documentation of __toString() we can't find any word about the non-implicit conversion from integer to string. http://fr.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring Previous Comments: ------------------------------------------------------------------------ [2009-03-25 22:46:29] fel...@php.net 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 ------------------------------------------------------------------------ [2009-03-25 22:42:08] fabien dot meynard at supinfo dot com Description: ------------ When we want to use __toString() method for an object we can't return a integer, that's a problem for example if we have a class named Zip and __toString() method have to return zipcode. I my example, seconde class represent the fix in php : we have to force implicit conversion from integer to string Reproduce code: --------------- <?php Class Zip { protected $zipcode = 33000; public function __toString() { return $this->zipcode; } } $zip = new Zip(); echo 'Zip : ' .$zip; ?> // and now the fix Class Zip2 { protected $zipcode = 33000; public function __toString() { return (string) $this->zipcode; } } Expected result: ---------------- Zip : 33000 Actual result: -------------- Catchable fatal error: Method Zip::__toString() must return a string value in /Users/fabienmeynard/- on line 13 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47781&edit=1