I'm new to PHP, an instructor made this Controller class, it's an MVC, and put a __Hospital(){}
without using it, is that necessary?
class Hospital{
private $cod;
private $nom;
private $dir;
public function __Hospital() {
}
public function _Hospital($cod, $nom, $dir) {
$this->cod = $cod;
$this->nom = $nom;
$this->dir = $dir;
}
public function getCod() {
return $this->cod;
}
public function getNom() {
return $this->nom;
}
public function getDir() {
return $this->dir;
}
public function setCod($cod) {
$this->cod = $cod;
}
public function setNom($nom) {
$this->nom = $nom;
}
public function setDir($dir) {
$this->dir = $dir;
}
}
The core idea of constructors as magic methods specifically in PHP; is to initialize the value of properties that identify or belong to a class.
EXAMPLE
Now it's not so much that it's wrong or not, but rather how the PHP interpreter is going to read it;
I quote:
citation example
Reference source
This way of declaring a constructor where it has the same name as the class is common, for example, although not limited to languages like Java; where the following is valid
Where in fact if you omit it it will mark an error when trying to compile the project similar to:
invalid method declaration