ID: 47781
Updated by: [email protected]
Reported By: fabien dot meynard at supinfo dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: macos x
PHP Version: 5.2.9
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
Previous Comments:
------------------------------------------------------------------------
[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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.