- Preloading
Preloading lets OpCache load and link classes, interfaces, and traits once at server startup using a script configured with the opcache.preload directive.
- Foreign Function Interface (FFI)
PHP 7.4 adds the ffi extension, whose FFI::cdef() and FFI::scope() methods call functions of C libraries from PHP, secured with ffi.enable and ffi.preload.
- Arrow Functions
Arrow functions declared with the new fn keyword are a concise syntax for closures that implicitly capture variables from the parent scope by value.
- Generators
Generators in PHP 7 can return a value read with getReturn(), delegate to other generators with yield from, and use yield as a right-associative operator.
- Anonymous Classes
PHP 7 introduces anonymous classes created with new class, shown as an in-place test stub for an abstract class and detected via ReflectionClass.
- Assertions
In PHP 7, assert() is a language construct controlled by the zend.assertions and assert.exception directives that can throw an AssertionError on failure.
- Group Use Declarations
Group use declarations in PHP 7 import several classes that share a namespace prefix with one use statement; trailing commas are allowed as of PHP 7.2.
Countable Interface and Internal Classes
The internal classes DOMNamedNodeMap, DOMNodeList, and ZipArchive now implement the Countable interface, so their objects work with the count() function.
is_countable()
The new is_countable() function checks whether a variable is an array or implements Countable and can be passed to count() without triggering a warning.
- Asynchronous Signal Handling
Calling pcntl_async_signals() enables asynchronous signal handling, so callbacks registered with pcntl_signal() run without the old ticks feature.
spl_object_id()
The new spl_object_id() function returns the identifier of an object as an integer, unique during its lifetime, as an alternative to spl_object_hash().
get_mangled_object_vars()
The new get_mangled_object_vars() function returns the properties of an object under their mangled names and avoids the problems of the (array) cast.
gettype and resources
Since PHP 7.2, gettype() returns resource (closed) for a variable that holds a closed resource instead of the unknown type result of earlier versions.
- Custom Object Serialization
The __serialize() and __unserialize() methods are a new mechanism for custom object serialization meant to replace __sleep(), __wakeup(), and Serializable.
is_object() and Incomplete Classes
As of PHP 7.2, is_object() returns true instead of false for an incomplete class, such as the __PHP_Incomplete_Class object produced by unserialize().
- Null Coalesce Operator
PHP 7 adds the null coalesce operator ??, a concise replacement for isset() checks with the ternary operator that supplies a fallback value for null.
- Null Coalescing Assignment Operator
The null coalescing assignment operator ??= complements ?? and assigns the right-hand operand to the left-hand operand only if the latter is null.
- Combined Comparison Operator
PHP 7 adds the combined comparison operator <=>, also called the spaceship operator, which returns -1, 0, or 1 and shortens usort() comparison functions.
- Weak References
The WeakReference class, with its create() and get() methods, holds a reference to an object that does not keep the garbage collector from destroying it.
- Numeric Literal Separator
The underscore can be used as a numeric literal separator, as in 1_000_000_000, in integers, floats, and hexadecimal, binary, and octal values.
- Trailing Commas in Function and Method calls
Since PHP 7.3, a trailing comma is allowed after the last argument of a function or method call, as it has long been allowed in array definitions.