PHP 函数 参数可缺省 参数初始化

来源:互联网 发布:安装mac os 编辑:程序博客网 时间:2024/06/06 07:12
public function __construct($repository = null, $transformer = null){    $this->repository = $repository;    $this->transformer = $transformer;}
public function __construct($repository = null, $transformer = null)

表示 $repository $transformer
 这两个参数是可缺省的,因为他有初值 NULL

如果仅是
public function __construct($repository, $transformer)

那么 $repository $transformer
这两个参数就一定要传入的


由于是可缺省参数,所以
new Class(); //
repository,transformer 初始化值为NULL
new Class(&var,&var);
都不会出错
0 0
原创粉丝点击