时间:2021-07-01 10:21:17 帮助过:3人阅读
class test{ public function __construct($host="127.0.0.1",$port="80") { echo 'host:'.$host."
"; echo 'port:'.$port; }}$data['host']='192.168.1.1';$data['port']='1212';$str=implode(',',$data);$obj=new test($str);
host:192.168.1.1,1212port:80
低级错误
$str 就一个变量啊,程序怎么会自动理解为两个呢
这么传参等于是你传了一个host变量192.168.1.1,1212 port变量没传 还是使用类默认的80
要这样写
class test{ public function __construct($host="127.0.0.1",$port="80") { echo 'host:'.$host."host:192.168.1.1
"; echo 'port:'.$port; } }$data['host']='192.168.1.1';$data['port']='1212';$ref = new ReflectionClass('test');$obj = $ref->newInstanceArgs($data);
"; echo 'port:'.$port; } } $data['host']='192.168.1.1';$data['port']='1212';//$str=implode(',',$data);//$obj=new test($str);$obj = test::new_object($data);
$ref = new ReflectionClass('test');
$obj = $ref->newInstanceArgs($data);