1. Database & Cryptography Functions: mysql_* & mcrypt_*
Status: Deprecated in PHP 5.5 / 7.1; Removed in PHP 7.0 / 7.2.
Old Code (PHP 5.x):
$res = mysql_query("SELECT * FROM items");
$enc = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB);
Modern Replacement (PHP 8.x):
// PDO database query
$stmt = $pdo->query("SELECT * FROM items");
$items = $stmt->fetchAll();
// OpenSSL encryption
$enc = openssl_encrypt($text, 'aes-256-cbc', $key, 0, $iv);
2. Dynamic Functions: create_function() & each()
Status: Deprecated in PHP 7.2; Removed in PHP 8.0.
Old Code:
// create_function replacement
$func = create_function('$a,$b', 'return $a + $b;');
// each() iteration
while (list($key, $val) = each($array)) { ... }
Modern Replacement:
// Anonymous Closure function
$func = fn($a, $b) => $a + $b;
// Standard foreach loop
foreach ($array as $key => $val) { ... }
3. POSIX Regex: split() & ereg_*()
Status: Deprecated in PHP 5.3; Removed in PHP 7.0.
Old Code:
$parts = split(':', $string);
$match = ereg('[a-z]', $string);
Modern Replacement:
$parts = explode(':', $string); // or preg_split()
$match = preg_match('/[a-z]/', $string);
4. Syntax Changes: Curly-Brace String Offsets & money_format()
Status: Curly-brace string access deprecated in PHP 7.4, removed in PHP 8.0. money_format() removed in PHP 7.4 in favor of NumberFormatter.
Old Code:
$char = $str{0}; // Fatal syntax error in PHP 8
$formatted = money_format('%i', $val);
Modern Replacement:
$char = $str[0]; // Square brackets
$fmt = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
$formatted = $fmt->formatCurrency($val, 'USD');
5. Implicit Non-Nullable Internal Parameters
Passing null to non-nullable scalar arguments of core internal functions (e.g. htmlspecialchars(null)) is deprecated in PHP 8.1 and throws deprecation notices or errors.
Related guides: PHP 5.6 to PHP 8 Migration Complete Compatibility Guide and CodeIgniter PHP 8 Migration Common Errors.
Let’s build your digital presence
Address
A45 Shraddha Society, Near SBI Bank, Dindoli, Surat, Gujarat-394210, India.
Phone
Our Office Location
A45 Shraddha Society, Near SBI Bank, Dindoli, Surat, Gujarat-394210, India.
Open in Google Maps