A typical use for this exception, is in conjunction with the is_callable() function.
(PHP 5 >= 5.1.0, PHP 7)
Exception thrown if a callback refers to an undefined function or if some arguments are missing.
A typical use for this exception, is in conjunction with the is_callable() function.
For example:
function foo($arg) {
$func = 'do' . $arg;
if (!is_callable($func)) {
throw new BadFunctionCallException('Function ' . $func . ' is not callable');
}
}
You can also throw BadMethodCallException within a method when certain pre-conditions to safely call that method are not met.
For example when a method <?php $foo->analyzeData(); ?> has been called but no data as previously been loaded (from file "import" for database, wherever from).
Direct known subclasses:
BadMethodCallException
So BadMethodCallException can be used in case the subject function is or should be a part of class / object - it's use defines the case more precisely.