x; }}$foo = new Caller();$a = $foo->test("/>
PHP头条
热点:

php幻术方法call详解


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

www.phpzy.comtrue/phprm/34507.htmlTechArticlephp幻术方法call详解 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(...

相关文章

PHP之友评论

今天推荐