{
    "slug": "removed_function",
    "term": "Removed PHP Function",
    "category": "php",
    "difficulty": "intermediate",
    "short": "Calling a function removed in a newer PHP version — causes a fatal error on upgrade and blocks modernisation of the PHP runtime.",
    "long": "PHP removes deprecated functions across major versions. Notable removals: PHP 7.0 removed mysql_* (use PDO/mysqli), PHP 8.0 removed create_function() (use closures), ereg() family (use preg_*), magic_quotes_gpc, get_magic_quotes_gpc(). PHP 8.1 deprecated passing null to non-nullable parameters. Rector can automatically migrate most removed function calls. Always check the PHP migration guides before upgrading and run PHPStan with the phpstan-deprecation-rules extension.",
    "aliases": [
        "deprecated function",
        "removed API",
        "mysql_query",
        "create_function"
    ],
    "tags": [
        "php",
        "compatibility",
        "migration",
        "legacy"
    ],
    "misconception": "Code that works on PHP 7.4 will work on PHP 8.0 — PHP 8.0 has significant breaking changes including removed functions, changed type handling, and stricter error handling.",
    "why_it_matters": "Using removed functions means your application will produce fatal errors on any server running the current PHP version — blocking security patches and performance improvements.",
    "common_mistakes": [
        "mysql_connect(), mysql_query(), mysql_fetch_array() — removed in PHP 7.0, use PDO.",
        "create_function() — removed in PHP 8.0, use fn() => or function() {}.",
        "ereg(), eregi(), ereg_replace() — removed PHP 7.0, use preg_match(), preg_replace().",
        "each() — removed PHP 8.0, use foreach or array_key_first()."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "deprecated_functions",
        "rector_automated",
        "pdo",
        "php_deployment_pipeline"
    ],
    "prerequisites": [
        "deprecated_functions",
        "php_compilation_pipeline",
        "rector_automated"
    ],
    "refs": [
        "https://www.php.net/manual/en/migration80.incompatible.php"
    ],
    "bad_code": "// Removed in PHP 7.0 — fatal error on modern PHP:\n$conn = mysql_connect('localhost', 'root', 'pass');\n$result = mysql_query('SELECT * FROM users', $conn);\nwhile ($row = mysql_fetch_assoc($result)) { /* ... */ }\nmysql_close($conn);\n\n// Removed in PHP 8.0:\n$fn = create_function('$x', 'return $x * 2;');\n$fn(5);",
    "good_code": "// Modern PDO — works on PHP 7.0-8.4+:\n$pdo = new PDO('mysql:host=localhost', 'root', 'pass');\n$stmt = $pdo->query('SELECT * FROM users');\nwhile ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { /* ... */ }\n\n// Modern closure:\n$fn = fn($x) => $x * 2;\n$fn(5);\n\n// Rector migrates automatically:\n// vendor/bin/rector process src --config rector.php",
    "quick_fix": "Run Rector with PHP_83 ruleset to detect removed functions — ereg(), each(), mysql_*(), mcrypt_*(), create_function() are all gone in PHP 7+/8+; Rector auto-migrates most of them",
    "severity": "high",
    "effort": "medium",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/removed_function",
        "html_url": "https://codeclaritylab.com/glossary/removed_function",
        "json_url": "https://codeclaritylab.com/glossary/removed_function.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": "[Removed PHP Function](https://codeclaritylab.com/glossary/removed_function) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/removed_function"
            }
        }
    }
}