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

Removed PHP Function

PHP PHP 7.0+ Intermediate
debt(d3/e2/b3/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3), Rector and PHPStan with php-compatibility rules flag removed functions automatically and reliably.

e2 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1) bumped to e2, most removals map to a direct replacement (ereg→preg_match, mysql_*→PDO needs slightly more), and Rector auto-migrates most cases.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3), the removed call sites are localised but mysql_* style usage can be sprinkled across legacy code, imposing a modest ongoing migration tax.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap most devs eventually learn' (t5), per the misconception developers assume PHP minor-to-major upgrades are safe; removed functions silently break on upgrade, a well-known gotcha.

About DEBT scoring →

Also Known As

deprecated function removed API mysql_query create_function

TL;DR

Calling a function removed in a newer PHP version — causes a fatal error on upgrade and blocks modernisation of the PHP runtime.

Explanation

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.

Common 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().

Code Examples

✗ Vulnerable
// Removed in PHP 7.0 — fatal error on modern PHP:
$conn = mysql_connect('localhost', 'root', 'pass');
$result = mysql_query('SELECT * FROM users', $conn);
while ($row = mysql_fetch_assoc($result)) { /* ... */ }
mysql_close($conn);

// Removed in PHP 8.0:
$fn = create_function('$x', 'return $x * 2;');
$fn(5);
✓ Fixed
// Modern PDO — works on PHP 7.0-8.4+:
$pdo = new PDO('mysql:host=localhost', 'root', 'pass');
$stmt = $pdo->query('SELECT * FROM users');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { /* ... */ }

// Modern closure:
$fn = fn($x) => $x * 2;
$fn(5);

// Rector migrates automatically:
// vendor/bin/rector process src --config rector.php

Added 16 Mar 2026
Edited 22 Mar 2026
Views 91
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 0 pings T 4 pings F 4 pings S 7 pings S 9 pings M 3 pings T 0 pings W 3 pings T 2 pings F 2 pings S 3 pings S 0 pings M 2 pings T 0 pings W 2 pings T 1 ping F 0 pings S 1 ping S 1 ping M 0 pings T 4 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
ChatGPT 1
ChatGPT 49 Amazonbot 7 Scrapy 7 Perplexity 5 Google 5 Ahrefs 3 Unknown AI 2 Claude 2 Meta AI 1 Qwen 1 Common Crawl 1
crawler 75 crawler_json 8
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ 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
📦 Applies To
PHP 7.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
ereg() ereg_replace(); mysql_connect() mysql_query(); each() in while loop; mcrypt_encrypt(); create_function() eval wrapper
Auto-detectable: ✓ Yes rector phpstan php-compatibility
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Line Tests: Update


✓ schema.org compliant