In fact, it is receiving a variable of type Person. Since the constructor is asking for an object of Pessoa
as a parameter, if anyone is to use the class pass anything else as a parameter, it will automatically receive an error.
Starting with version 7 of PHP
you can or can not put types in your variables.
For example, if you want to do a function that must return a int
, you can do this:
public function getId(): int{
return 0;
}
And if you want to get 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 type int
and you can also receive null
, you can put a question mark before the type:
public function setId(?int $id){
$this->id = $id;
}