Call to Undefined Function/Method
debt(d5/e3/b3/t7)
Closest to 'specialist tool catches it' (d5). The detection_hints list phpstan and composer as tools — PHPStan is a static analysis tool (specialist, not a default linter) that catches calls to undefined functions/methods. However, the why_it_matters note says extension-based errors are environment-specific and often only appear in production, meaning runtime detection can lag. PHPStan catches the static case; environment mismatch slips through to runtime, so d5 is the best fit.
Closest to 'simple parameterised fix' (e3). The quick_fix says to declare required extensions in composer.json (e.g. ext-gd, ext-intl), add extension_loaded() guards, and verify with php -m. This is a small, localised fix — updating composer.json and adding a guard — but may touch multiple files if the function is called in several places, making it slightly more than a one-liner but still within one component.
Closest to 'localised tax' (b3). The applies_to scope covers web and cli contexts broadly, but the burden is localised: once extensions are declared in composer.json and guards are added, the rest of the codebase is unaffected. It's a persistent reminder to check extension availability but doesn't impose a systemic structural cost on every future change.
Closest to 'serious trap' (t7). The misconception field states explicitly: 'Call to undefined function always means a typo — it often means a PHP extension isn't enabled or a file wasn't included.' This contradicts the intuitive reading of the error message. A competent developer will instinctively search for a typo or missing include, missing the extension-availability root cause entirely, especially since dev and production environments differ. This is a well-documented gotcha that contradicts how similar errors behave in other languages.
TL;DR
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
Why It Matters
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
// ext-gd not installed in production
$img = imagecreatetruecolor(800, 600);
// Fatal: Call to undefined function imagecreatetruecolor()
// 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);