extending a superclass' constructor within a subclass in php [duplicate]
Possible Duplicate:
Call parent constructor before child constructor in PHP
I have a class that manages my database connection. It has a constructor that fetches the database details from a config file:
class Database {
function __construct(){
//perform magic
}
}
I am now extending this class to create a class for managing user creation and validation, and I need it to still do the things the superclass does, but with some extras.
class Members {
function __construct(){
//perform super class magic
// then perform your own magic
}
}
What is the correct way to go about this?
Use parent::__construct
:
class Members {
public function __construct(){
parent::__construct();
// your code
}
}
Obviously you'll need to pass any arguments on that the parent class requires.
精彩评论