Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > php技巧

PHP魔术方法之__call与__callStatic使用方法

来源:中文源码网    浏览:118 次    日期:2024-05-08 06:32:39
【下载文档:  PHP魔术方法之__call与__callStatic使用方法.txt 】


PHP魔术方法之__call与__callStatic使用方法
核心代码
//魔术方法__call
/*
$method 获得方法名
$arg 获得方法的参数集合
*/
class Human {
private function t(){
}
public function __call($method,$arg){
echo '你想调用我不存在的方法',$method,'方法
';
echo '还传了一个参数
';
echo print_r($arg),'
';
}
public static function __callStatic($method,$arg){
echo '你想调用我不存在的',$method,'静态方法
';
echo '还传了一个参数
';
echo print_r($arg),'
';
}
}
$ha = new Human();
//example1
$ha->t(1,2,3);
echo '
';
//example2
$ha->say('a','b','c');
echo '
';
//example3
$ha::run('d','e','f');
你想调用我不存在的方法t方法
还传了一个参数
Array ( [0] => 1 [1] => 2 [2] => 3 )
你想调用我不存在的方法say方法
还传了一个参数
Array ( [0] => a [1] => b [2] => c )
你想调用我不存在的run静态方法
还传了一个参数
Array ( [0] => d [1] => e [2] => f )

相关内容