The function I’m calling with call_user_func is supposed to return FALSE. So how do I detect errors if the callable is invalid?
(Side note: Why didn’t they have this throw an exception rather than return an error code? Or is there a way to “catch” errors? I have an error handle. Should I have it throw exceptions for me?)
If you want to check if the function or method to be called really exists, you can use
is_callablebefore callingcall_user_func. You may wrap the whole thing in a function for easy reuse:You asked in a comment about why PHP raises errors instead of using exceptions. I think that’s because exceptions were introduced only in PHP5, so most PHP functions rely on error reporting. There seems to be a way around that, as the manual indicates: