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

Reply via email to