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 for App\foo unless prefixed with \foo()
  • Conditional definition never loaded

Minimal examples

BAD — reproduces the problem

php
namespace App;\n$ch = curl_init(); // looks for App\\curl_init if not imported/fallback fails for undefined

FIXED — safer pattern

php
namespace App;\nif (!extension_loaded('curl')) {\n    throw new RuntimeException('ext-curl is required');\n}\n$ch = \\\\curl_init();

Step-by-step diagnosis

  1. Note the exact function name from the fatal error.
  2. Run php -m (CLI) or check extension_loaded() / phpinfo for extension functions.
  3. Confirm which SAPI failed—CLI and FPM can load different modules.
  4. 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.

bash
# 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.

php
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.json require (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

Relevant ZendStudio.net tools