PHP __call vs method_exists

前端 未结 5 1065
花落未央
花落未央 2020-12-18 21:55

The Project I\'m working on contains something like a wrapper for call_user_func(_array) which does some checks before execution. One of those checks is method_exists (In Ca

5条回答
  •  被撕碎了的回忆
    2020-12-18 22:26

    Have a look at is_callable().

    But no, if the __call() method only handles some names, then you would need some other way of checking if the call will succeed.

    Might I suggest a interface with the method canCall($function), or something? Then check if the class implements the interface. If it doesn't, just use is_callable().

提交回复
热议问题