Removed PHP Function
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
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
18
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 6
Perplexity 3
Google 3
Unknown AI 2
ChatGPT 2
Ahrefs 1
Also referenced
How they use it
crawler 14
crawler_json 3
Related categories
⚡
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