php魔术方法call详解
作者:zccst
class Caller
{
private $x = array(1, 2, 3);
public function __call($m, $a)
{
print "Method $m called:n";
var_dump($a);
return $this->x;
}
}
$foo = new Caller();
$a = $foo->test(1, "2", 3.4, true);
var_dump($a);
输出结果:
Method test called:n
array
0 => int 1
1 => string '2' (length=1)
2 => float 3.4
3 => boolean true
array
0 => int 1
1 => int 2
2 => int 3
批注:
__call() 是PHP里的一个魔术方法,当你调用一个类里的方法,而该方法又不存在里,就会自动调用__call() ;
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn