ScotlandPHP 2019

The BadFunctionCallException class

(PHP 5 >= 5.1.0, PHP 7)

Introduction

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

Class synopsis

BadFunctionCallException extends LogicException {
/* Inherited properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Inherited methods */
final public Exception::getMessage ( void ) : string
final public Exception::getPrevious ( void ) : Throwable
final public Exception::getCode ( void ) : mixed
final public Exception::getFile ( void ) : string
final public Exception::getLine ( void ) : int
final public Exception::getTrace ( void ) : array
final public Exception::getTraceAsString ( void ) : string
public Exception::__toString ( void ) : string
final private Exception::__clone ( void ) : void
}
add a note add a note

User Contributed Notes 4 notes

up
9
tom at tomwardrop dot com
9 years ago
A typical use for this exception, is in conjunction with the is_callable() function.
up
1
evguenia dot chagnon at gmail dot com
1 year ago
For example:

function foo($arg) {
    $func = 'do' . $arg;
    if (!is_callable($func)) {
        throw new BadFunctionCallException('Function ' . $func . ' is not callable');
    }
}
up
0
roland at mxchange dot org
1 year ago
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).
up
-5
Dawid Krysiak
7 years ago
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.
To Top