| re: OOP: constructors of base class in new()
Ramprasad A Padmanabhan wrote:[color=blue]
> Hi all,
>
> I am a php newbie, ( doing perl all time till now ). I am a bit
> confused OOP in php.
>
> Suppose I create an instance of a class with the new() function the
> cronstuctor is called .. fine
>
> Now if the class *extends* another class the constructor of base class
> is not called. But is there a way I can tell php to execute all
> constructors of base classses when I call new()[/color]
I can't see why would you want to do that. If the classes are so different
that each subclass needs a new contructor, then you don'te need inheritance,
but separate classes. If, on the other hand, you need the subclass to call
the parent's contructor, instead of its own, then don't give the subclass a
constructor. E.g:
class DarthVader {
function DarthVader() {} // constructor
}
class LukeSkywalker extends DarthVader {
// no constructor
}
new LukeSkywalker() will then call the DarthVader() function.
Berislav
--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo. |