What exactly is the difference between the is_callable and function_exists in PHP?

后端 未结 5 1703
长发绾君心
长发绾君心 2021-02-01 01:22

I am working on a project, in which I am using a deprecated function from the older version. But don\'t want my script to stop if used in the older version.

So I am check

5条回答
  •  伪装坚强ぢ
    2021-02-01 01:43

    One more different:

    If you have a class which uses __call magic method, the is_callable($object, $method) will always return true for anything because __call basically accepts every method name. And as you might already know, method_exists will return false for this if the method is not defined in the class.

    This is especially annoying if you use CakePHP Model class as they implemented __call magic method to provide magic queries, but not cool if you want the method to be absolutely defined.

提交回复
热议问题