您不能在PHP类中放置两个带有唯一参数签名的__construct函数.我想这样做:
class Student
{
protected $id;
protected $name;
// etc.
public function __construct($id){
$this->id = $id;
// other members are still uninitialized
}
public function __construct($row_from_database){
$this->id = $row_from_database->id;
$this->name = $row_from_database->name;
// etc.
}
}
Run Code Online (Sandbox Code Playgroud)
在PHP中执行此操作的最佳方法是什么?