Beste Möglichkeit, mehrere Konstruktoren in PHP zu erstellen

Sie können nicht zwei __construct-Funktionen mit eindeutigen Argumentsignaturen in eine PHP-Klasse einfügen. Ich würde das gerne machen:

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.
   }
}

Was ist der beste Weg, um dies in PHP zu tun?

Antworten auf die Frage(19)

Ihre Antwort auf die Frage