__toString( ) set a string value for the object that will be used if the object is ever used as a string. : __toString « Class « PHP






__toString( ) set a string value for the object that will be used if the object is ever used as a string.

 
<?
    class Cat {
            public function _ _toString( ) {
                    return "This is a cat\n";
            }
    }

    $toby = new Cat;
    print $toby;
?>
  
  








Related examples in the same category

1.Defining a class's stringification
2.Using the __toString() Method