in reply to Can we call a Child Class Member functions using Parent Class Object
Yes, but you shouldn't.
To call any function in a class aka package (basically a class is a package) you write class::function($yourobject, ...). You need to add your object as the first parameter if the function is a method, because methods expect this.
You shouldn't do this because usually child classes add functionality that the parent class doesn't have. Later on you might change the child class and for example add a variable that this function you want to call needs. Bamm, your program doesn't work anymore because the parent object doesn't have such a variable.
If your child class function is valid for the parent as well, why don't you move the function to the parent?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can we call a Child Class Member functions using Parent Class Object
by chromatic (Archbishop) on Jun 07, 2011 at 18:24 UTC |