PHP error guide
PHP Fatal Error: Call to undefined function
Error summary
PHP tried to call a function that is not defined in the current runtime—often a missing extension (`curl_init`), a typo, or a namespaced call that does not fall back as you expect.
What it means
PHP tried to call a function that is not defined in the current runtime—often a missing extension (curl_init), a typo, or a namespaced call that does not fall back as you expect.
What the error means
The function name could not be resolved. For extension functions, the extension is not loaded. For user functions, the file was not included or the name/namespace is wrong.
Why PHP produces it
Function calls are resolved at runtime. Missing extensions and incorrect namespaces both surface as “undefined function” rather than a dedicated “extension missing” message.
PHP version notes
On PHP 7+, many fatals are Error exceptions (“Uncaught Error: Call to undefined function…”) rather than only the older bare Fatal error format.
Most common causes
- Required PHP extension not installed/enabled (
ext-curl,ext-mbstring, etc.) - Typo in function name
- Namespaced code calling
foo()which looks forApp\foounless prefixed with\foo() - Conditional definition never loaded
Minimal examples
BAD — reproduces the problem
namespace App;\n$ch = curl_init(); // looks for App\\curl_init if not imported/fallback fails for undefined
FIXED — safer pattern
namespace App;\nif (!extension_loaded('curl')) {\n throw new RuntimeException('ext-curl is required');\n}\n$ch = \\\\curl_init();
Step-by-step diagnosis
- Note the exact function name from the fatal error.
- Run
php -m(CLI) or checkextension_loaded()/ phpinfo for extension functions. - Confirm which SAPI failed—CLI and FPM can load different modules.
- Search for the function definition or polyfill in the project.
Fixes
Fix #1: Install/enable the extension
Install the package for your OS/SAPI and restart PHP-FPM or Apache.
# Example on RHEL-like systems (package names vary)\nsudo dnf install php-curl\nsudo systemctl restart php-fpm
Fix #2: Fix namespace resolution
Call global functions with a leading backslash inside namespaces.
namespace App\\\\Http;\n\n$ch = \\\\curl_init('https://example.com');
Common mistakes when fixing it
- Installing an extension for CLI PHP while the site uses a different FPM PHP version
- Assuming Composer
ext-*platform checks ran in the same environment that serves HTTP
How to prevent it
- Declare required extensions in
composer.jsonrequire(ext-curl) - Fail fast with
extension_loaded()during app bootstrap in production builds
Web server / environment notes
CLI and web SAPIs; extension availability often differs per SAPI
Tags: cli,fpm,apache,nginx,docker,composer
Categories
Related PHP errors
-
Class not found
Fatal error: Uncaught Error: Class "%s" not found in %s:%d -
Composer platform requirements not satisfied
Your Composer dependencies require a PHP version ">= 8.2.0". You are running 8.1.29. -
Call to undefined function
Fatal error: Uncaught Error: Call to undefined function %s() in %s:%d
Relevant ZendStudio.net tools
- Composer Platform Checker Paste composer.json to list PHP constraints and ext-* platform requirements without running Compose…
- PHP Configuration Inspector Paste php --ini output or selected directive lines to identify loaded ini files and key limits.
- PHP Error Matcher Paste a full PHP error, warning, SQLSTATE, or cURL message to find the best ZendStudio.net troubles…