Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

toString method in class php

Mon Oct 27, 2008 12:16 am

Code:
<?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;
?>




Post a reply
  Related Posts  to : toString method in class php
 Define class helper class to check the method existance     -  
 define a Class with a Method     -  
 invoke class method dynamically in php     -  
 what is string toString()     -  
 java abstract class,concrete class and interface     -  
 relationship between the Canvas class and the Graphics class     -  
 inner class that is a member of an outer class?     -  
 Define class inside another class C++     -  
 What is an abstract method     -  
 What is a native method     -  

Topic Tags

PHP OOP