PHP overriding methods

PHP overriding methods

Function 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"
PHP objects & properties
Every class in PHP must have new instances or object created. This object must be assigned to a variable.
PHP access control modifier
Access control modifiers restrict the functions and classes to be accessed.
PHP constructors & destructors
Constructor methods for classes can be declared. Classes having a constructor method can call this method on each new object.
Post your comment
Discussion Board
overriding in php

In Object Oriented Programming (OOP), Overloading is defining functions that have similar signatures, yet have different parameters. Overriding is only pertinent to derived classes, where the parent class has defined a method and the derived class wishes to override that function.

In PHP, you can only overload methods using the magic method __call.
jitendra pal 09-5-2012