Class Tostring

 
    <?phpclass Person {
    function getName()  {
        return "Joe";
    }
    function getAge() {
        return 31;
    }
    function __toString() {
        $desc  = $this->getName()." (age ".
        $desc .= $this->getAge().")";
        return $desc;
    }
}$person = new Person();
print $person;
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.