Sunday, 28 September 2014

Object Oriented Programming in PHP : Function Overriding

Function definitions in child classes override definitions with the same name in parent classes. In a child class, we can modify the definition of a function inherited from parent class.




In the follwoing example getPrice and getTitle functions are overriden to retrun some values.

function getPrice(){
       echo $this->price . "<br/>";
       return $this->price;
    }
    function getTitle(){
       echo $this->title . "<br/>";
       return $this->title;
    }
 
 
 

No comments:

Post a Comment