PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
class Foo extends Bar {
function Foo($args='some argument') {
// do something
}
//some other functions
}
class Bar {
function Bar($arg1=null,$arg2=null) {
//do some vital stuff
}
}
?>
How is the Bar constructor called? or do I just to Bar::Bar("arg1","arg2); ??
If class Foo has no constructor then class Bar's constructor would be called automatically.
To call class Bar's constructor from within class Foo's constructor do
parent::Bar();
Jay wrote:Here's an even smaller point: If you change the name of the Bar class, how does parent::Bar() still work?
I should think before I post.
If parent::method() was aimed at a method and not the constructor it would survive a name change. If pointed at the constructor, and you changed the name of the class (but not the constructor) it would still work - but of course the constructor name is likely to be changed also as you rightly point out.
hehe good points... and some less thought through... McGruff: I found that link you gave me before I posted, but I guess I skimmed through it a bit too fast.
A big problem when searching for solutions is that no matter how much I look, I will allways get a better solution here at this awesome forum!
the above point about calling parent::method() when method() is the constructor will all be solved with php5... with the nice __construct() default method... then we can change the names as much as we want.