_toString() PHP function [closed]

PuLs333

New Member
Here is my _toString() function. I can't find anything wrong with it but I keep getting an error in my browser when I try to echo an obj of this class saying "Catchable fatal error: Object of class Fraction could not be converted to string in."\[code\]public function _toString (){ $str = ""; if(($this->num/$this->den) >= 1) { $tmp = ((int)($this->num/$this->den)); $str .= "{$tmp} "; } if ($this->num%$this->den != 0) { $tmp =$this->num % $this->den; $str .= "{$tmp} / {$this->den}"; } return $str;}\[/code\]Could it be something wrong with my function or is it something else? Thanks.(This is for a fraction class I am trying to represent in a string. $num is the numerator and $den is the denominator)
 
Top