PHP __call vs method_exists

前端 未结 5 1043
花落未央
花落未央 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:16

    method_exists tries two things:

    • Searches for the method name in the class's function table. Those are the function foo() {} type methods.
    • Checks if the class (the C code) has a (C code) get_method() function and if it has invoke it to let the class implementation decide.

    You'd need the latter. But this get_method()is not "extended" to the php script code, i.e. there is no way to let get_method() call some user defined php script code (And what would this php code return?).

    So the answer to my best knowledge is: No, it's not possible (yet?).

    The implementation of ZEND_FUNCTION(method_exists) can be found in zend/zend_builtin_functions.c and is I think fairly readable even if you don't know C but PHP.

提交回复
热议问题