phpseverity: critical
Call to undefined function

PHP Call to undefined function — Function does not exist or extension not loaded

Fatal error: Call to undefined function

97% fixable~10 mindifficulty: beginner

Verified against PHP 8.3 documentation, PHP extension loading guide, PHP namespaces manual · Updated June 2026

> quick_fix

Check the function name for typos, confirm the required PHP extension is loaded (`php -m`), and verify the function is in scope (correct namespace or `use` statement).

<?php
// Check if function exists before calling
if (function_exists('mb_strtolower')) {
    $result = mb_strtolower($str);
} else {
    // fallback or throw meaningful error
    $result = strtolower($str);
    error_log('mb_string extension not loaded');
}

// Check extension is loaded
if (!extension_loaded('intl')) {
    throw new RuntimeException('intl extension is required');
}

What causes this error

PHP throws a fatal 'Call to undefined function' error when you call a function that the PHP runtime cannot find. This happens due to: a typo in the function name, calling a function from a PHP extension that is not installed or not enabled in php.ini, calling a user-defined function before it is declared, or calling a namespaced function without the correct namespace prefix or use statement.

> advertisementAdSense placeholder

How to fix it

  1. 01

    step 1

    Check the function name for typos

    PHP function names are case-insensitive but must be spelled correctly. The error message contains the exact function name PHP could not find. Compare it against the PHP manual. Common typo: `array_key_exists` vs `array_keys_exists` (wrong).

  2. 02

    step 2

    Verify the required extension is loaded

    Run `php -m` in your terminal to list loaded modules. For `mb_strtolower` you need `mbstring`; for `curl_init` you need `curl`; for `imagecreate` you need `gd`. If missing, install/enable it: `sudo apt-get install php-mbstring` on Ubuntu, or uncomment `extension=mbstring` in php.ini.

  3. 03

    step 3

    Check the namespace and use statements

    In PHP 5.3+ namespaced code, `MyLib\str_pad()` is different from the global `str_pad()`. If you call a global function from inside a namespace without a leading backslash, PHP first looks in the current namespace. Fix: use `\str_pad()` or add `use function str_pad;` at the top.

  4. 04

    step 4

    Check function declaration order

    Unlike JavaScript, PHP functions declared with `function foo()` are available throughout the file (hoisted). However, functions inside conditionals or class methods are only declared when that code runs. Conditional function declarations must be declared before use.

  5. 05

    step 5

    Verify Composer autoload is included

    If calling a function from a Composer package, ensure `require __DIR__ . '/vendor/autoload.php';` is at the top of your entry script. Without autoload, classes and their static methods are undefined.

How to verify the fix

  • Run `php -m | grep <extension>` to confirm the extension is loaded
  • Run the script from the CLI — the fatal error should not appear
  • Add `function_exists('functionName')` check in code to confirm availability before calling

Why Call to undefined function happens at the runtime level

PHP resolves function calls at runtime by looking up the function name in a global function table. When you call a function, PHP checks: (1) the current namespace's function table, then (2) the global function table. If the function is not found in either location — because the extension providing it is not loaded, the file defining it has not been included, or the name has a typo — PHP raises a fatal E_ERROR with the 'Call to undefined function' message and halts execution. Unlike class autoloading (spl_autoload_register), PHP has no built-in mechanism to autoload individual functions.

Common debug mistakes for Call to undefined function

  • Calling `mb_` string functions without enabling the mbstring extension
  • Calling `curl_init()` without enabling the curl extension
  • Misspelling `array_key_exists` as `array_keys_exists` or similar
  • Calling a function from a namespace without a leading backslash for global functions

When Call to undefined function signals a deeper problem

The lack of a function autoloading mechanism in PHP (only class autoloading exists) means that function availability is environment-dependent and not statically verifiable in the language. This is why modern PHP development prefers static methods on classes or callable objects — they benefit from Composer autoloading and IDE type checking. The PHP community has shifted toward using classes and namespaces for all library code precisely because the function table is a global, untyped, unautomated namespace.

Editor's take

Call to undefined function is PHP's way of telling you that a function name you invoked doesn't exist in the current execution context. In modern PHP (8.0+), the most common cause isn't a typo — it's a missing `use` statement for a namespaced function, or calling a function from an extension that isn't loaded in your current PHP configuration. Production servers frequently have different extensions enabled than your local development environment — `imagecreatetruecolor()` requires GD, `curl_init()` requires cURL, and `mb_strlen()` requires mbstring. The `php -m` command shows loaded modules and should be part of your deployment checklist. In Laravel and Symfony applications, this error often surfaces when a helper function from a package is used but the package's service provider hasn't been registered, or `composer dump-autoload` hasn't been run after a new dependency was added. The error is also common when migrating between PHP versions: functions deprecated in 7.x get removed in 8.x (like `each()`, `create_function()`, and `mysql_*` functions). Check `php --ri extension_name` to verify extension availability on your target server. If the function exists locally but not in production, the fix is ensuring your `php.ini` or Docker image includes the required extension — not copying the function's implementation from the PHP source.

By Bikram Nath · Curator · Updated June 2026

Frequently asked questions

Why does the function work on my local machine but not on the server?

Different PHP installations enable different extensions. Your local XAMPP/Wamp/Homebrew PHP may include mbstring, intl, or gd by default; a minimal Linux server PHP package may not. Run `phpinfo()` or `php -m` on both environments and compare the extension list.

Is 'Call to undefined function' a fatal error?

Yes — it is a PHP Fatal error (E_ERROR). Execution stops immediately at the line that calls the undefined function. It cannot be caught with a try-catch block in PHP 7; however, in PHP 7+, you can intercept it with set_error_handler() or use a custom exception handler, but the execution of the current script still terminates.

How do I check which PHP extensions are available?

Command line: `php -m` lists all loaded modules. In a script: `phpinfo()` shows all loaded extensions in a browser-readable page, or `get_loaded_extensions()` returns an array you can var_dump().

disclosure:Errordex runs AdSense, has zero third-party affiliate or sponsored links, and occasionally links to the editor’s own paid digital products (clearly labelled). Every fix is cross-referenced against the official sources listed in the “sources” sidebar before it ships. If a fix here didn’t work for you, please email so we can update the page.