Removed PHP Function
debt(d3/e2/b3/t5)
Closest to 'default linter catches the common case' (d3), Rector and PHPStan with php-compatibility rules flag removed functions automatically and reliably.
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.
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.
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.
Also Known As
TL;DR
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
Why It Matters
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
// 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);
// 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