__call()和call_user_func_array()
2019-07-20 本文已影响0人
幻无虚生
<?php
class Index{
public function price($day,$price){
echo "出去旅游".$day."天,总共用了".$price.'元';
}
}
class Travel{
public $price;
public function index(){
}
public function __construct()
{
$this->price=new Index();
}
public function __call($pub,$age){
if(method_exists($this->price,$pub)){
call_user_func_array([$this->price,$pub],$age);
}
}
}
$travle=new Travel();
$travle->price('10','10000');