|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-03-25 22:46 UTC] felipe@php.net
[2009-03-25 22:53 UTC] fabien dot meynard at supinfo dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 13:00:01 2025 UTC |
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