Article

Migrating from PHP 5 to PHP 7

Practical PHP 5→7 upgrade focus: removed ext/mysql and ereg, engine changes, and why 7.4 is often the bridge runtime.

PHP 7.0 removed large pieces of the PHP 5 ecosystem. If production is still on 5.6 (or earlier), treat PHP 7 as a deliberate intermediate milestone even when the business goal is PHP 8—many mechanical failures surface first at 7.0. Official entry points: migration70 through migration74.

Hard removals that stop the boot

  • ext/mysql (mysql_connect, mysql_query, …) — migrate to mysqli/PDO
  • POSIX regex: ereg*, split — migrate to preg_*
  • Many obsolete INI toggles and SAPIs differences—compare php -i dumps
# LEGACY
$r = mysql_query('SELECT 1');

# MODERN
$r = $mysqli->query('SELECT 1');
# or PDO query/exec with exceptions enabled

Behavioral shifts worth regression tests

PHP 7 tightened many engine behaviors (foreach by-reference edge cases, integer semantics on 64-bit, throwable hierarchy with Error). Add smoke tests around session bootstrap, autoloading, and unserialize of stored payloads before calling the 5→7 cut “done.”

Why teams pause on 7.4

PHP 7.4 is EOL, but as a bridge in CI it still helps: typed properties and limited modern syntax arrive while you finish deleting 5.x APIs. Do not plan long-term hosting on 7.4—continue to PHP 8. Flagship context: PHP 5 to modern PHP.

Use compatibility checker against 7.4 and 8.x rulesets, and map fatals via mysql_connect removed.

Related scanners: PHP Version Compatibility Checker · PHP Deprecated Checker.

Related reading