PHP 7.2: Major Features

PHP 7.2 tightens everyday engineering: a real object type hint, parameter type widening (drop parameter types in overrides while staying LSP-safe), richer PDO debugging for emulated prepares, LDAP extended operations, a modern sockets addrinfo API, and first-class libsodium bindings. At the same time it removes mcrypt from core (PECL only) and promotes several legacy patterns to warnings or deprecations. Budget time for count() hygiene, get_class(null), casts between arrays and objects with numeric keys, and any code still on mcrypt.

Table of Contents


object type

You can declare object for parameters and return types—any instance satisfies it. This pairs with return-type covariance / parameter contravariance rules as PHP evolved across 7.x.

function acceptsAnyObject(object $x): void {}

Parameter type widening

Implementations may omit parameter type hints that appear on the parent/interface method (still contravariance-safe). You cannot narrow or change to an unrelated type on abstract/interface chains—PHP will reject incompatible overrides.

PDO: richer debugDumpParams()

PDOStatement::debugDumpParams() can show the full SQL sent to the server for emulated prepares, including bound values—useful when debugging query construction (only when emulation is on).

LDAP extended operations (EXOP)

New helpers such as ldap_exop(), ldap_exop_passwd(), ldap_exop_whoami(), ldap_parse_exop(), plus constants like LDAP_EXOP_START_TLS—covering common EXOP flows without raw LDAP glue code.

Sockets: socket_addrinfo_*

socket_addrinfo_lookup(), socket_addrinfo_connect(), socket_addrinfo_bind(), socket_addrinfo_explain() wrap getaddrinfo()-style resolution and connection setup—prefer this over manual AF_INET parsing when you need modern address families.

Sodium (libsodium) in core

The Sodium extension ships with PHP 7.2+, exposing libsodium’s AEAD, hashing, and KDF primitives. Treat it as the default path for new crypto instead of mcrypt (removed from core—see below).

Notable extensions & stdlib

  • utf8_encode() / utf8_decode() moved to core string functions (no longer tied to needing the XML extension).
  • mail() / mb_send_mail() accept header arrays as well as strings.
  • DBA gains LMDB backend support.
  • GD: imageantialias() with system libgd; imagegd() stores truecolor more faithfully.
  • session_module_name('user') now raises recoverable error instead of failing silently.

Practical recipes

Guard count()

if (is_array($x) || $x instanceof \Countable) {
    $n = count($x);
}

(is_countable() arrives in PHP 7.3—on 7.2 use the explicit check.)

Safe get_class()

$cls = is_object($obj) ? get_class($obj) : self::class;

Backward incompatible changes

Core & types

  • number_format() no longer returns -0 for odd floating edge cases—UI/tests that asserted that string may change.
  • Casting arrays/objects with numeric keys: accessing $obj->{0} / $obj->{'0'} and mirrored (array) access is consistent for integer-ish keys (see migration72 incompatible).
  • get_class(null) now warns; omit the argument or pass an object.
  • count() (and sizeof()) on non-countable types emits E_WARNING—code that relied on count(null) === 0 breaks noisily.
  • spl_autoload_register() parity: deprecations around legacy __autoload (see deprecations).

Extensions

  • MCrypt extension removed from core—install from PECL if you truly must, but migrate to OpenSSL/Sodium.

Deprecations (fix early)

High-signal items (full list: migration72 deprecated):

  • __autoload()—use spl_autoload_register().
  • Unquoted barewords that used to be notice are now warning (future: Error).
  • Legacy create_function(), each(), string assert(), single-argument parse_str(), read_exif_data() alias, gmp_random(), png2wbmp / jpeg2wbmp, and more.

Other changes & build

  • Autoconf ≥ 2.64 on Unix; --with-pdo-oci no longer needs Instant Client version in the flag; removed unused --enable-gd-native-ttf.
  • MCrypt → PECL; adopt Sodium/OpenSSL for crypto work.

Closing thoughts

PHP 7.2 is a good moment to delete mcrypt code paths, grep for count( on possibly-null values, and fix get_class(null). Then continue toward 7.3+ for JsonException, is_countable(), and heredoc quality-of-life.