Article
Migrating from PHP 8.0 to PHP 8.1
PHP 8.1 upgrade notes: resource-to-object migrations, null parameter deprecations, mysqli exceptions, and $GLOBALS restrictions.
PHP 8.1 is where many “it boots on 8.0” applications start noisy again: resources become objects, passing null to non-nullable internal parameters is deprecated, and mysqli defaults to exceptions. Official guide: migration81.
Resource → object migrations
Extensions such as finfo, FTP, IMAP, LDAP, PostgreSQL, and others now return objects. Replace is_resource($x) checks with falsey/failure checks or instanceof against the documented class (for example FTP\Connection).
# LEGACY
$ftp = ftp_connect('example.com');
if (!is_resource($ftp)) { throw new RuntimeException('ftp'); }
# MODERN
$ftp = ftp_connect('example.com');
if ($ftp === false) { throw new RuntimeException('ftp'); }
# $ftp is FTP\Connection on success in 8.1+
Null to non-nullable internal parameters
Code that relied on coercing null into string/int parameters of internal functions emits deprecations in 8.1. Fix call sites—see null-to-non-nullable params and error guide.
# LEGACY
strlen($maybeNull); // deprecated when $maybeNull is null
# MODERN
strlen($maybeNull ?? '');
$GLOBALS and signature edges
Writing to the entire $GLOBALS array is forbidden; element access remains fine. Optional parameters declared before required ones become harder errors. Internal method return types may require #[\ReturnTypeWillChange] during transitional polyfills.
MySQLi exception mode
Default error mode moves toward exceptions. Audit code that expected silent false returns; either handle exceptions or set reporting explicitly during migration.
Scan with deprecated checker before promoting images. Next: 8.1→8.2.
Related scanners: PHP Version Compatibility Checker · PHP Deprecated Checker.
Related reading
- Composer Modernization Center Add Composer to legacy PHP projects, migrate includes to autoloading, set platform constraints, and replace a…
- PHP 5 to Modern PHP: Complete Incremental Migration Guide A deep, production-minded path from PHP 5.x codebases to supported PHP 8.x: removed extensions, charset, PDO,…
- PHP Security Modernization for Legacy Applications Upgrade inherited PHP security practices: prepared statements, password hashing, sessions, CSRF, XSS escaping…
- PHP 7 to PHP 8 Migration Guide Deep guide to PHP 8.0 breaking changes that matter for PHP 7 applications, with upgrade tactics through suppo…
- Inheriting a Legacy PHP Application A first-30-days playbook for developers handed an unfamiliar PHP codebase: runtime truth, risk triage, and sa…