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