Blog
1. If you just want to make sure you can call it, use is_callable. If you need to make sure that the method exists by that name (meaning it’s not callable just through a magic method) then use both.
2. If you just want to know if the method exists, not caring whether you can call it at that point, then method_exists alone is enough.
3. If you want to call the method and you don’t care why or how it’s callable, but just that it is, then use is_callable alone.
Just notice the purpose of each: is_callable tells you whether calling it will abort the script with an error, while method_exists tells you if that method was actually hard-coded in a particular class, not caring if it’s gonna explode in your face when you try to call it.
]]>if method_exist(…) && is_callable(…)
]]>One thing I often see when re-factoring PHP applications, is the improper use of the method_exists() function, and I think this needs a little bit of clarification….
]]>