在 PHP 中执行多个构造函数的最佳方法
2022-08-30 05:56:42
						不能在 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.
   }
}
在PHP中执行此操作的最佳方法是什么?