The following try..catch is meant to run a method if it exists and run a different method if it doesn’t..
$heading = new HeadingMan();
try {
if (!is_callable($heading->{$this->breadcrumbs->getCrumb(3)}())) {
throw new Exception ('<b>Error - HeadingMan class can not handle: </b>' . $this->breadcrumbs->getCrumb(3));
}
$heading->{$this->breadcrumbs->getCrumb(3)};
}
catch (Exception $e) {
$heading->latest();
}
However, the catch statement always triggers, and throws a new exception (runs the catch portion of the statement).
How do I check a method exists in a class by using a series of function calls
$this->breadcrumbs->getCrumb(3);
to get the name of the function.?
$bool = method_exists($class,$method);
http://php.net/manual/en/function.method-exists.php