From: fabien dot meynard at supinfo dot com Operating system: macos x PHP version: 5.2.9 PHP Bug Type: Class/Object related Bug description: __toString() problem with an integer return
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 bug report at http://bugs.php.net/?id=47781&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47781&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47781&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47781&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47781&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47781&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47781&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47781&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47781&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47781&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47781&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47781&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47781&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47781&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47781&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47781&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47781&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47781&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47781&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47781&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47781&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47781&r=mysqlcfg
