#47781 [Opn->Bgs]: __toString() problem with an integer return
| From: | felipe@php.net | Date: | Wed, 25 Mar 2009 22:46:29 +0000 |
| Subject: | #47781 [Opn->Bgs]: __toString() problem with an integer return | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-135129@lists.php.net to get a copy of this message | ||
ID: 47781
Updated by: felipe@php.net
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