parent::__construct() - does the order matter?

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!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

parent::__construct() - does the order matter?

Post by Luke »

Does it matter whether you call the parent constructer like this:

Code: Select all

function __construct(){
// Do stuff
parent::__construct();
}
as opposed to this:

Code: Select all

function __construct(){
parent::__construct();
// Do stuff
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It only matters in how your class needs things. i.e. if you class needs information that would be filled in by the parent's constructor, then you need to construct it first. If it doesn't matter to the child then it doesn't really matter when you call it. I personally try to call the parent's constructor first always.
Post Reply