PHP overriding methodsFunction overriding is used when a class has some methods and derived class wants same methods with different behavior. So, using overriding you can completely change the behavior of parent class.
Function overriding can be implemented by extending a class and rewriting a function which existed in the parent class.
class Shape { function myShape() { return "Shape"; } } class Square extends Shape { function myShape() { return "Square"; } } $shape = new Shape; $square = new Square; echo($shape->myShape()); //"Shape" echo($square->mySquare()); //"Square" ?>
|