/errors/php/call-to-undefined-function
PHP Fatal error: Uncaught Error: Call to undefined function
- tool
- PHP
- exit code
- 255
- versions
- PHP 7.0+ (thrown as Error), PHP 8.x
- os
- any
PHP Fatal error: Uncaught Error: Call to undefined function NAME() means PHP found no function called NAME when the call ran. Since PHP 7 this is an Error exception; if nothing catches it, the script stops with a fatal error. Most often the function comes from an extension that is not loaded (mb_strlen needs mbstring, curl_init needs curl, mysqli_connect needs mysqli), or from a file or namespace that was not included.
What the message looks like
On the CLI the message names the function and the file and line of the call, followed by a stack trace:
PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /var/www/app/index.php:3With display_errors on in a web request the same text appears without the PHP prefix.
Find out why
php -m # modules loaded by the CLI
php --ini # which php.ini files the CLI reads
php -r 'var_dump(function_exists("mb_strlen"), extension_loaded("mbstring"));'Fixes by cause
| Function | Cause | Fix |
|---|---|---|
| mb_*, curl_*, mysqli_*, gd image*, intl | Extension not installed or not enabled | Install the extension package for your PHP version, enable it in php.ini (extension=NAME), restart PHP-FPM or the web server |
| mysql_connect, mysql_query | Removed in PHP 7.0 | Rewrite with mysqli or PDO |
| Your own helper | Defining file not loaded | require_once the file, or add it to Composer autoload "files" |
| App\Utils\slugify | Namespaced function | Call \App\Utils\slugify() or add use function App\Utils\slugify; |
Inside a namespace, an unqualified call such as slugify() looks for CurrentNamespace\slugify first and then falls back to the global function; it never looks in other namespaces.
To fail gracefully when an optional extension is missing, check before calling:
if (!function_exists('mb_strlen')) {
throw new RuntimeException('The mbstring extension is required');
}