1

How can I make the parent constructor run before the child's constructor? ( Code: )

class database{
    public function __construct(){
        // Connect to database
    }
}

class child extends database{
    public function __construct(){
        // Do something
    }
}

I want it to connect to the database and then run the child's constructor, is that possible?

4

2 に答える 2

6

parent::__construct()child の先頭に追加し__construct()ます。

于 2013-02-27T16:21:44.330 に答える
2

このような:

class child extends database{
    public function __construct(){
        parent::__construct();
        // Do something
    }
}
于 2013-02-27T16:22:41.020 に答える