class toString : toString « Class « PHP






class toString

<?php

class 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;
?>


           
       








Related examples in the same category