首页 > 编程 > PHP > 正文

PHP __call()方法

2019-11-11 07:53:14
字体:
来源:转载
供稿:网友

使用对象内部方法的时候,调用的方法不存在就会导致程序退出不能继续执行;在类内部使用__call()方法,使用类的方法不存在时不会导致程序退出。

__call()方法的例子:

class Test { public function __call($name, $arguments) { // TODO: Implement __call() method. PRint "函数: $name(参数: "; print_r($arguments); echo ")不存在!<br/>"; }}$test = new Test();$test->demo("one", 2, array(1,2,3));

页面打印出来的值

函数: demo(参数: Array ( [0] => one [1] => 2 [2] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) )不存在!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表