Default values in the php constructor

class human{
  public $name = "leo";
  public $age = "25";
  public function __construct($name,$age){
    $this->name=$name;
    $this->age=$age;
  }
}

means that when this human is instantiated, if no parameters are given, use leo, 25.
found that do not, instantiation must be given a value.
$x = new human ();
wants to use the default name=leo age=25, but can"t!

Php
Apr.01,2022

_ _ construct ($name = 'leo', $age =' 25') {
Parameter default

Menu