魔术方法之__call与__callStatic方法

<?php
class human{
private function t(){
}


/**
     * 魔术方法__call
     *
     * @param string $method 获得方法名
     * @param string $arg 获得方法的参数集合
     */
    public function __call($method, $params){
        echo '你想调用我不存在的方法', $method, '方法';
        echo '还传了一个参数';
        print_r($params);
    }

    //魔术方法__callStatic
    public static function __callStatic($method, $params){
        echo '你想调用我不存在的', $method, '静态方法';
        echo '还传了一个参数';
        print_r($params),'';
    }
}

$li=new human();
$li->say(1, 2, 3);

/*
__call是调用不可见(不存在或无权限)的方法时,自动调用
$li->say(1, 2, 3);
-----没有say()方法---->
 __call('say', array(1, 2, 3))运行
*/

human::cry('痛哭', '鬼哭', '号哭');

/*
__callStatic 是调用不可见的静态方法时,自动调用.
Human::cry('a', 'b', 'c');
----没有cry方法---> 
Human::__callStatic('cry', array('a', 'b', 'c'));
*/

?>

  

转载于:https://www.cnblogs.com/qq254980080/p/9384401.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值