{
    "slug": "php_call_to_undefined",
    "term": "Call to Undefined Function/Method",
    "category": "php",
    "difficulty": "beginner",
    "short": "'Call to undefined function' means the function wasn't declared, the file wasn't loaded, or the PHP extension providing it isn't installed.",
    "long": "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.",
    "aliases": [],
    "tags": [
        "php",
        "errors",
        "extensions"
    ],
    "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()."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "php_fatal_error",
        "composer",
        "php_class_not_found",
        "php_extensions"
    ],
    "prerequisites": [
        "composer",
        "php_extensions"
    ],
    "refs": [
        "https://www.php.net/manual/en/function.extension-loaded.php"
    ],
    "bad_code": "// ext-gd not installed in production\n$img = imagecreatetruecolor(800, 600);\n// Fatal: Call to undefined function imagecreatetruecolor()",
    "good_code": "// In composer.json:\n// \"require\": {\"ext-gd\": \"*\"}\n\n// Runtime check:\nif (!extension_loaded('gd')) {\n    throw new \\RuntimeException('GD extension required. Install php-gd.');\n}\n$img = imagecreatetruecolor(800, 600);",
    "quick_fix": "Declare required extensions in composer.json (ext-gd, ext-intl etc). Use extension_loaded() guards. Check with php -m for installed extensions.",
    "severity": "high",
    "effort": "low",
    "created": "2026-03-22",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php_call_to_undefined",
        "html_url": "https://codeclaritylab.com/glossary/php_call_to_undefined",
        "json_url": "https://codeclaritylab.com/glossary/php_call_to_undefined.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Call to Undefined Function/Method](https://codeclaritylab.com/glossary/php_call_to_undefined) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php_call_to_undefined"
            }
        }
    }
}