PHP

    xiaoxiao2021-03-26  22

    使用对象内部方法的时候,调用的方法不存在就会导致程序退出不能继续执行;在类内部使用__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 ) ) )不存在!

    转载请注明原文地址: https://ju.6miu.com/read-661955.html

    最新回复(0)