php 构造函数中的默认值

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

本意是,在这个human 实例化的时候,如果不给任何参数,就使用 leo , 25 .
发现,做不要,实例化的时候必须给值。
$x =new human();
希望使用默认的 name=leo age=25 ,做不到?!

慕村225694
浏览 596回答 1
1回答

慕慕森

__construct($name = 'leo', $age = '25'){参数默认值
打开App,查看更多内容
随时随地看视频慕课网APP