# PHP Fatal error: Uncaught Error: Call to undefined function

**Code:** `Call to undefined function` · **Category:** PHP · **Seen on:** PHP, Linux

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_connect` removed in PHP 7, `each()` in PHP 8)
- Calling a namespaced function without `use function` or full name

## Quick fix

1. Install/enable the extension: `sudo apt install php8.2-curl` (match your version) and restart FPM/Apache
2. Check `phpinfo()` from the web server, not just `php -m` on CLI
3. Replace removed functions (`mysql_*` → PDO/mysqli)
4. Check includes/autoload and namespaces

## Detailed fix by platform

### PHP

1. 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

1. **Function** — Built-in (extension) or yours?
2. **Runtime** — Which PHP version/ini does the web server use?
3. **Loading** — Is the defining file included?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/call-to-undefined-function)
