我想在子类中调用父构造函数。这是System.php文件中的父类:
class System
{
private $db_host;
private $db_name;
private $db_user;
private $db_pass;
private $connection;
protected $glb;
public function __construct()
{
$this->db_host = "localhost";
$this->db_name = "signage";
$this->db_user = "root";
$this->db_pass = "";
$this->glb =& $GLOBALS;
}
}
以及User.php文件中的子类:
require_once "System.php";
class User extends System
{
public $user_id;
public $user_fullname;
public $user_password;
public $user_email;
public $user_token;
public $user_type;
public function __construct()
{
parent::__construct();
}
}
返回此错误:
Fatal error: Uncaught Error: Cannot call constructor in C:\xampp\htdocs\signage\classes\User.php:14 Stack trace: #0 C:\xampp\htdocs\signage\login.php(6): User->__construct() #1 {main} thrown in C:\xampp\htdocs\signage\classes\User.php on line 14
问题出在哪里?我见过constructors and distructors in php manual,那里一切正常。