The BadFunctionCallException class

(PHP 5 >= 5.1.0, PHP 7)

简介

Exception thrown if a callback refers to an undefined function or if some arguments are missing.

类摘要

BadFunctionCallException extends LogicException {
/* 继承的属性 */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* 继承的方法 */
final public string Exception::getMessage ( void )
final public Throwable Exception::getPrevious ( void )
final public int Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}

User Contributed Notes

roland at mxchange dot org 30-Mar-2017 09:31
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).
evguenia dot chagnon at gmail dot com 26-Jan-2017 09:14
For example:

function foo($arg) {
    $func = 'do' . $arg;
    if (!is_callable($func)) {
        throw new BadFunctionCallException('Function ' . $func . ' is not callable');
    }
}
Dawid Krysiak 03-Feb-2011 11:35
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.
tom at tomwardrop dot com 16-Nov-2009 04:42
A typical use for this exception, is in conjunction with the is_callable() function.