firstname = $firstname; $this->lastname = $lastname; $this->age = isset($age) ? $age : -1; } // Magic getter public function __get(string $val): mixed { return isset($this->$val) ? $this->$val : "Unknown attribut"; } // Magic setter public function __set(string $val, mixed $value): void { if (!(isset($this->$val) && gettype($this->$val) == gettype($value))) return; switch ($val) { case 'age': $this->$val = $value > -1 ? $value : $this->$val; break; default: $this->$val = $value; break; } } /** * Retrieve the formated name */ public function getFormattedName(): string { return sprintf("%s %s", strtoupper($this->lastname), ucfirst(strtolower($this->firstname))); } }