【发布时间】:2015-04-08 08:54:28
【问题描述】:
我有 __construct($parameter)
public function __construct($nick) {
$query = "SELECT * FROM Users WHERE nick='".$nick."'";
$result = App::runQuery($query);
$user = $result->fetch_object();
$this->id = $user->id;
$this->nick = $user->nick;
$this->email = $user->email;
$this->password = $user->password;
$this->birthDay = $user->birthDay;
$this->sex = $user->sex;
$this->about = $user->about;
$this->city = $user->city;
$this->photo = $user->photo;
$this->following = $user->following;
$this->followers = $user->followers;
$this->statu = $user->statu;
}
现在我想要一个没有参数的默认构造函数:
public function __construct() {
$this->id = NULL;
$this->nick = NULL;
$this->email = NULL;
$this->password = NULL;
$this->birthDay = NULL;
$this->sex = NULL;
$this->about = NULL;
$this->city = NULL;
$this->photo = NULL;
$this->following = NULL;
$this->followers = NULL;
$this->statu = NULL;
}
但是出了点问题,我收到这样的错误:
Fatal error: Cannot redeclare User::__construct() in /Applications/MAMP/htdocs/xxx/Application/User.php on line 33
如何同时拥有两个带参数和不带参数的构造函数?
【问题讨论】:
-
虽然两年后您可能不再从事此工作,但此代码中存在明显的 SQL 注入错误