Skip to content

/errors/php/call-to-undefined-function

PHP Fatal error: Uncaught Error: Call to undefined function

The commands on this page have not been executed by our verification runner yet.updated
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:

text
PHP Fatal error:  Uncaught Error: Call to undefined function mb_strlen() in /var/www/app/index.php:3

With display_errors on in a web request the same text appears without the PHP prefix.

Find out why

bash
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

FunctionCauseFix
mb_*, curl_*, mysqli_*, gd image*, intlExtension not installed or not enabledInstall the extension package for your PHP version, enable it in php.ini (extension=NAME), restart PHP-FPM or the web server
mysql_connect, mysql_queryRemoved in PHP 7.0Rewrite with mysqli or PDO
Your own helperDefining file not loadedrequire_once the file, or add it to Composer autoload "files"
App\Utils\slugifyNamespaced functionCall \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:

php
if (!function_exists('mb_strlen')) {
    throw new RuntimeException('The mbstring extension is required');
}

Sources