Cheetah
is_callable.php
Go to the documentation of this file.
1 <?php
2 
8 if (!function_exists('is_callable')) {
9  function is_callable($var, $syntax_only=false)
10  {
11  if ($syntax_only)
12  {
13  /* from The Manual:
14  * If the syntax_only argument is TRUE the function only verifies
15  * that var might be a function or method. It will only reject simple
16  * variables that are not strings, or an array that does not have a
17  * valid structure to be used as a callback. The valid ones are
18  * supposed to have only 2 entries, the first of which is an object
19  * or a string, and the second a string
20  */
21  return (is_string($var) || (is_array($var) && count($var) == 2 && is_string(end($var)) && (is_string(reset($var)) || is_object(reset($var)))));
22  }
23  else
24  {
25  if (is_string($var))
26  {
27  return function_exists($var);
28  }
29  else if (is_array($var) && count($var) == 2 && is_string($method = end($var)))
30  {
31  $obj = reset($var);
32  if (is_string($obj))
33  {
34  $methods = get_class_methods($obj);
35  return (bool)(is_array($methods) && in_array(strtolower($method), $methods));
36  }
37  else if (is_object($obj))
38  {
39  return method_exists($obj, $method);
40  }
41  }
42  return false;
43  }
44  }
45 }
46 
47 ?>
php