redirecting to other methods when calling non-existing methods

后端 未结 3 800
甜味超标
甜味超标 2021-01-14 16:18

If I call $object->showSomething() and the showSomething method doesn\'t exist I get a fata error. That\'s OK.

But I have a show()

3条回答
  •  太阳男子
    2021-01-14 17:15

    You can use the function method_exists(). Example:

    class X {
        public function bar(){
            echo "OK";
        }
    }
    $x = new X();
    if(method_exists($x, 'bar'))
        echo 'call bar()';
    else
        echo 'call other func';

提交回复
热议问题