In fact it is receiving a variable of type Person. As the constructor is asking for an object of the uncle Pessoa
as a parameter, if whoever uses the class passes anything else as a parameter, they will automatically receive an error.
Starting from version 7 of PHP
you may or may not put types in your variables.
For example, if you want to do a function that must return a int
, can do so:
public function getId(): int{
return 0;
}
and if you want to receive a parameter that must be int
, you would do so:
public function setId(int $id){
$this->id = $id;
}
If you need your parameter to be of the type int
and may also receive null
, you can put a question mark before the type:
public function setId(?int $id){
$this->id = $id;
}
Assign type to parameters
– rray