PHP 7.2 Upgrade Guide: Breaking Changes, New Features, Deprecated Functions, and Extension Updates
This article provides a comprehensive overview of PHP 7.2's upgrade changes, detailing backward‑incompatible core modifications, new language and extension features, deprecated functions, altered behaviours, added functions and classes, removed extensions, and updated INI and Windows support, all essential for backend developers.
The document outlines the major changes introduced in PHP 7.2, organized into several sections.
1. Backward‑incompatible changes
Core gettype() now returns resource (closed) for closed resources instead of unknown type . Objects of class __PHP_Incomplete_Class are now recognised by is_object() as objects. Support for Netware OS has been removed. When casting arrays to objects, integer keys become property names; casting objects to arrays or using get_object_vars() now converts integer properties to numeric keys. Undefined constant usage now triggers a warning‑level error (later an error). Minimum supported Windows versions are Windows 7 and Windows Server 2008 R2. Native trait property compatibility checks have been dropped. The word object can no longer be used as a class name.
BcMath bcmod() now behaves like fmod() , returning the fractional part (e.g., bcmod('4','3.5') returns 0.5 ).
Hash hash_hmac() , hash_hmac_file() , hash_pbkdf2() and hash_init() with HASH_HMAC no longer support non‑cryptographic hash algorithms.
JSON If the second argument of json_decode() is null , the JSON_OBJECT_AS_ARRAY option is now enabled.
Session Removal of register_globals related code; the character ! can be used in $_SESSION keys. Many session functions now return boolean values and accept empty parameters, improving error handling. INI settings for sessions must be changed via ini_set() ; changes after headers are sent are ignored.
Standard On 64‑bit machines, the random sequence produced by mt_rand() and rand() may differ for the same seed.
2. New features
Core Method and interface parameter types can be omitted (covariant return types). Abstract classes can now override abstract methods from parent abstract classes. Trailing commas are allowed in grouped namespaces. Object type hints are permitted.
DBA LMDB backend support added.
JSON Support for JSON_INVALID_IGNORE and JSON_INVALID_UTF8_SUBSTITUTE added.
OCI8 Transparent Application Failover (TAF) for Oracle databases is now supported.
PCRE Internal option j now modifies PCRE_DUPNAMES .
Sodium New cryptographic extension added.
SQLite3 Support for writing BLOBs added.
Standard Argon2 password hashing support via PASSWORD_ARGON2I and related options. Windows support for proc_nice() added.
Zip Read/write encrypted archives with new methods: ZipArchive::setEncryptionName($name, $method[, $password]) , ZipArchive::setEncryptionIndex($index, $method[, $password]) . New constants: ZipArchive::EM_NONE , EM_AES_128 , EM_AES_192 , EM_AES_256 . Ability to accept passwords from zip stream contexts. ZipArchive::count() method added.
3. Deprecated features
Core __autoload() deprecated; use spl_autoload_register() . each() deprecated; replace with foreach() . create_function() deprecated; use anonymous functions. Configuration file track errors deprecated.
Exif read_exif_data() deprecated; use exif_read_data() .
GD png2wbmp() and jpeg2wbmp() deprecated.
GMP gmp_random() deprecated; use gmp_random_bits() or similar.
Intl INTL_IDNA_VARIANT_2003 deprecated; use INTL_IDNA_VARIANT_UTS46 .
Mbstring Configuration mbstring.func_overload deprecated.
Standard Calling parse_str() without arguments deprecated. Calling assert() with a string argument deprecated; use expressions.
4. Changed functions
Standard password_hash() now supports PASSWORD_ARGON2I and related default options. password_verify() , password_get_info() , and password_needs_rehash() work with Argon2 hashes. mail() and mb_send_mail() accept an $extra_header array following RFC 2822. count() now throws a warning for invalid parameters. pack() and unpack() support float and double on big‑ and little‑endian machines. number_format() no longer prefixes zero values with a minus sign.
XML utf8_encode() and utf8_decode() moved to the standard extension.
5. New functions
Core stream_istty() , sapi_windows_vt100_support() added.
DOM DomNodeList::count() and DOMNamedNodeMap::count() added (Countable).
FTP ftp_append() added.
GD imagesetclip() , imagegetclip() , imageopenpolygon() , imageresolution() , imagecreatefrombmp() , imagebmp() added.
Hash hash_hmac_algos() added.
Mbstring mb_chr() , mb_ord() , mb_scrub() added.
OCI8 oci_register_taf_callback() and oci_unregister_taf_callback() added for TAF support.
Sockets socket_addrinfo_lookup() , socket_addrinfo_connect() , socket_addrinfo_bind() , socket_addrinfo_explain() added.
SPL spl_object_id() added.
6. Removed extensions
Mcrypt The mcrypt extension is deprecated and moved to PECL; it is no longer maintained.
7. Other extension updates
EXIF Support added for additional camera brands (Samsung, DJI, Panasonic, Sony, Pentax, Minolta, Sigma/Foveon, AGFA, Kyocera, Ricoh, Epson). exif_read_data() and exif_thumbnail() now accept streams as the first argument.
GD Removed --enable-gd-native-ttf configure option. imagegd() now stores true‑color images as true‑color instead of converting to palette. imageantialias() supported when compiled with system libgd.
Mbstring mb_check_encoding() and mb_convert_encoding() now accept arrays and process recursively.
PDO_OCI Configuration syntax --with-pdo-oci no longer requires Oracle client libraries.
pdo_sqlite Use sqlite3_prepare_v2() and sqlite3_close_v2() instead of older functions.
8. New global constants
Core: PHP_FLOAT_DIG , PHP_FLOAT_EPSILON , PHP_FLOAT_MIN , PHP_FLOAT_MAX , PHP_OS_FAMILY .
Fileinfo: FILEINFO_EXTENSION .
GD: IMG_EFFECT_MULTIPLY , IMG_BMP .
PCRE: PREG_UNMATCHED_AS_NULL .
Standard: PASSWORD_ARGON2_DEFAULT_MEMORY_COST , PASSWORD_ARGON2_DEFAULT_TIME_COST , PASSWORD_ARGON2_DEFAULT_THREADS , PASSWORD_ARGON2I .
9. INI file handling changes
sql.safe_mode removed.
realpath_cache_size default set to 4096 k.
opcache.fast_shutdown removed; fast shutdown is now always enabled.
10. Windows support
VT100 console mode support added.
11. Build system
Minimum supported autoconf version is 2.64.
For the original source, see https://github.com/php/php-src/blob/PHP-7.2/UPGRADING .
Beike Product & Technology
As Beike's official product and technology account, we are committed to building a platform for sharing Beike's product and technology insights, targeting internet/O2O developers and product professionals. We share high-quality original articles, tech salon events, and recruitment information weekly. Welcome to follow us.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.