How to check a variable to see if it can be called as a method in class in PHP

1 Answer

0 votes
// bool is_callable(mixed $var [, bool $syntax_only = false 
//                  [, string &$callable_name ]] )

class c 
{

  function f() 
  {
      echo "f() from class c";
  }
}

$obj = new c();

$method_name = array($obj, 'f');

echo "<pre>";
var_dump(is_callable($method_name, true, $callable_name));  
echo "</pre>";

echo $callable_name;


/*
run: 

bool(true)

c::f 

*/

 



answered Jun 30, 2016 by avibootz
...