__call() __callStatic() 的用法

class whether{

	static public function tianqi($area){
		echo $area.'的天气预报';
	}

	static public function __callStatic($func,$argu){

		self::tianqi($func);

	}

}


if(isset($_GET[method])){
	$method=$_GET[method];
	whether::$method();
}



class whether{

	static public function tianqi($area){
		echo $area.'的天气预报';
	}

	 public function __call($func,$argu){

		self::tianqi($func);

	}

}

$a=new whether();
if(isset($_GET[method])){
	$method=$_GET[method];
	$a->$method();
}

以上两个分别是 天气预报 的 写法



class Human {
    public function hello() {
        echo 'hello<br />';
    }

    private function t() {
    }

    public static function __callStatic($method,$argu) {
        echo '你想调用一个不存在或不权调用的静态方法',$method,'<br />';
        echo '你调用时还传了参数<br />';
        print_r($argu);
    }

    public function __call($method,$argu) {
        echo '你想调用一个我不存在或不权调用的方法',$method,'<br />';
        echo '你调用时还传了参数<br />';
        print_r($argu);
    }
 
}

$lisi = new Human();

$lisi->hello();
$lisi->say(1,2,3);

$lisi->t('a','b','c');


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



*/


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值