← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Call to Undefined Function/Method

php PHP 4.0+ Beginner

TL;DR

'Call to undefined function' means the function wasn't declared, the file wasn't loaded, or the PHP extension providing it isn't installed.

Explanation

This fatal error happens when: (1) calling a function that doesn't exist — typo or not yet defined, (2) calling a function from a file not yet loaded — use require/autoload, (3) calling a function from a PHP extension not installed/enabled (e.g. imagecreatetruecolor without ext-gd), (4) calling a method on a wrong type (calling string methods on null — PHP 8 throws TypeError). Extension functions: use extension_loaded('gd') to check. Static method errors: 'Call to undefined method' — check class name, method visibility, and namespace.

Common Misconception

Call to undefined function always means a typo — it often means a PHP extension isn't enabled or a file wasn't included.

Why It Matters

Extension-based errors are environment-specific and often only appear in production where PHP extensions differ from development.

Common Mistakes

  • Not declaring extension dependencies in composer.json require section.
  • Calling instance methods statically or vice versa.
  • Using functions from optional extensions without checking extension_loaded().

Code Examples

✗ Vulnerable
// ext-gd not installed in production
$img = imagecreatetruecolor(800, 600);
// Fatal: Call to undefined function imagecreatetruecolor()
✓ Fixed
// In composer.json:
// "require": {"ext-gd": "*"}

// Runtime check:
if (!extension_loaded('gd')) {
    throw new \RuntimeException('GD extension required. Install php-gd.');
}
$img = imagecreatetruecolor(800, 600);

Added 22 Mar 2026
Views 22
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S
No pings yet today
Amazonbot 7 Unknown AI 3 Google 3 Perplexity 3 ChatGPT 1 Meta AI 1
crawler 16 crawler_json 1 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Declare required extensions in composer.json (ext-gd, ext-intl etc). Use extension_loaded() guards. Check with php -m for installed extensions.
📦 Applies To
PHP 4.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
imagecreate|iconv|intl_|curl_
Auto-detectable: ✓ Yes phpstan composer
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✗ Manual fix Fix: Low Context: File

✓ schema.org compliant