New Features
PHP Core
Typed properties
Class properties now support type declarations.
The above example will enforce that
$user->id can only be
assigned
int values and
$user->name can
only be assigned
string values.
Arrow functions
Arrow functions provide a
shorthand syntax for defining functions
with implicit by-value scope binding.
Limited return type covariance and argument type contravariance
The following code will now work:
Full variance support is only available if autoloading is used. Inside a
single file only non-cyclic type references are possible, because all
classes need to be available before they are referenced.
Null coalescing assignment operator
Numeric literal separator
Numeric literals can contain underscores between digits.
Weak references
Weak references allow the programmer to retain a reference to an object
that does not prevent the object from being destroyed.
Allow exceptions from __toString()
Throwing exceptions from __toString()
is now permitted. Previously this resulted in a fatal error. Existing
recoverable fatal errors in string conversions have been converted to
Error exceptions.
CURL
CURLFile now supports stream wrappers in addition
to plain file names, if the extension has been built against libcurl >= 7.56.0.
FFI
FFI is a new extension, which provides a simple way to call
native functions, access native variables, and create/access
data structures defined in C libraries.
Hash
Added crc32c hash using Castagnoli's polynomial.
This CRC32 variant is used by storage systems, such as
iSCSI, SCTP, Btrfs and ext4.
Multibyte String
Added the mb_str_split() function, which provides
the same functionality as str_split(), but operating
on code points rather than bytes.
PDO
The username and password can now be specified as part of the PDO DSN for
the mysql, mssql, sybase, dblib, firebird and oci drivers. Previously this
was only supported by the pgsql driver. If a username/password is specified
both in the constructor and the DSN, the constructor takes precedence.
It is now possible to escape question marks in SQL queries to avoid them
being interpreted as parameter placeholders. Writing ??
allows sending a single question mark to the database and e.g. use the
PostgreSQL JSON key exists (?) operator.
PDO_SQLite
PDOStatement::getAttribute(PDO::SQLITE_ATTR_READONLY_STATEMENT)
allows checking whether the statement is read-only, i.e. if it doesn't modify
the database.
PDO::setAttribute(PDO::SQLITE_ATTR_EXTENDED_RESULT_CODES, true)
enables the use of SQLite3 extended result codes in PDO::errorInfo()
and PDOStatement::errorInfo().
SQLite3
Added SQLite3::lastExtendedErrorCode()
to fetch the last extended result code.
Added SQLite3::enableExtendedResultCodes($enable = true),
which will make SQLite3::lastErrorCode()
return extended result codes.
Standard
Custom object serialization
A new mechanism for custom object serialization has been added, which
uses two new magic methods: __serialize
and __unserialize.
The new serialization mechanism supersedes the
Serializable interface,
which will be deprecated in the future.
Array merge functions without arguments
array_merge() and array_merge_recursive()
may now be called without any arguments, in which case they will return an empty array.
This is useful in conjunction with the spread operator, e.g. array_merge(...$arrays).
proc_open() now accepts an array instead of a
string for the command. In this case the process will be opened
directly (without going through a shell) and PHP will take care of
any necessary argument escaping.
proc_open() now supports
redirect and null descriptors.
argon2i(d) without libargon
password_hash() now has the argon2i and argon2id implementations
from the sodium extension when PHP is built without libargon.