PHP __call vs method_exists

overloading, php

Solution

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()`.

Problem

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 Case the supplied first argument is an instance of a class and the second is a method name) The other is_callable. The function will throw an exception if one of those checks fails. My Code contains an array with function names (setFoo, setBar, etc.) and the php magic function for overloading (__call) which handles setting, replacing and deletion of certain variables (better certain array elements). The Problem: method_exists will return false if the function is not defined. Do I have any chance to get a true if the __call function does proper handling of the request?

Original source