PHP Fatal error: Uncaught Error: Call to undefined function
PHP can’t find the function you called — usually a missing extension, missing include, or namespace issue.
Meaning
If the function is built into a PHP extension (mysqli_connect, curl_init, mb_strlen, imagecreatefromjpeg), the extension isn’t installed/enabled for the PHP version actually running. Otherwise, the file defining it wasn’t loaded or the name/namespace is wrong.
Common causes
- PHP extension not installed or not enabled (mysqli, curl, mbstring, gd, intl)
- CLI and web server use different PHP versions/php.ini
- File with the function not included / autoloaded
- Function removed in newer PHP (e.g.
mysql_connectremoved in PHP 7,each()in PHP 8) - Calling a namespaced function without
use functionor full name
⚡ Quick fix
- Install/enable the extension:
sudo apt install php8.2-curl(match your version) and restart FPM/Apache - Check
phpinfo()from the web server, not justphp -mon CLI - Replace removed functions (
mysql_*→ PDO/mysqli) - Check includes/autoload and namespaces
Detailed fix by platform
PHP
- Find which extension is missing:bash
php -v && php -m | grep -i -E 'curl|mysqli|mbstring|gd|intl' sudo apt install php8.2-curl php8.2-mbstring php8.2-mysql sudo systemctl restart php8.2-fpm
Code examples
Check whether an extension function exists at runtime
php
foreach (['curl_init', 'mb_strlen', 'mysqli_connect', 'imagecreatetruecolor', 'intl_get_error_code'] as $fn) {
echo str_pad($fn, 24), function_exists($fn) ? "OK\n" : "MISSING\n";
}
echo 'php.ini: ', php_ini_loaded_file(), "\n";Run it through the web server (not CLI) — CLI and FPM often load different php.ini files.
Replace removed mysql_* functions with PDO
php
// ❌ PHP 7+: Call to undefined function mysql_connect()
$link = mysql_connect('localhost', 'user', 'pass');
// ✅
$pdo = new PDO('mysql:host=localhost;dbname=app;charset=utf8mb4', 'user', 'pass', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);How to diagnose
- Function — Built-in (extension) or yours?
- Runtime — Which PHP version/ini does the web server use?
- Loading — Is the defining file included?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026