您的位置:首页 > 编程语言 > PHP开发

php 魔术方法 __call

2016-03-14 13:57 621 查看
PHP5默认不支持方法的重载
所以利用__call来实现

class A{
public function test1($parameters){
echo '接收一个参数';
echo "<br/>";
var_dump($parameters);
}

public function test2($parameters){
echo '接收两个参数';
echo "<br/>";
var_dump($parameters);
}

//这里提示一个__call
//_call 当一个对象调用某个方法,而该方法不存在,
//则系统会自动调用__call

function __call($method,$parameters){
var_dump($parameters);
if($method=="test"){
if(count($parameters)==1){
$this->test1($parameters);
}else if(count($parameters)==3)
{
$this->test2($parameters);
}
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: