__call()
__call()函数是php类的默认魔法函数,__call() 在一个对象的上下文中,如果调用的方法不存在的时候,它将被触发:
1 <?php 2 class MethodTest { 3 public function __call($name, $arguments) { 4 // Note: value of $name is case sensitive. 5 echo "Calling object method '$name' " 6 . implode(', ', $arguments). "\n"; 7 } 8 } 9 $obj = new MethodTest; 10 $obj->runTest('in object context');
运行结果:
Calling object method 'runTest' in object context
浙公网安备 33010602011771号