当前位置:Gxlcms > PHP教程 > php幻术方法call详解

php幻术方法call详解

时间:2021-07-01 10:21:17 帮助过:9人阅读

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() ;

人气教程排行