# Language Features

> Section in “New and Extended Functionality” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/language-features/>

## In this section

- [Preloading](https://php7explained.com/new-and-extended-functionality/language-features/preloading/index.html.md): 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)](https://php7explained.com/new-and-extended-functionality/language-features/foreign-function-interface-ffi/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/arrow-functions/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/generators/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/anonymous-classes/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/assertions/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/group-use-declarations/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/countable-interface-and-internal-classes/index.html.md): The internal classes DOMNamedNodeMap, DOMNodeList, and ZipArchive now implement the Countable interface, so their objects work with the count() function.
- [is_countable()](https://php7explained.com/new-and-extended-functionality/language-features/is_countable/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/asynchronous-signal-handling/index.html.md): Calling pcntl_async_signals() enables asynchronous signal handling, so callbacks registered with pcntl_signal() run without the old ticks feature.
- [spl_object_id()](https://php7explained.com/new-and-extended-functionality/language-features/spl_object_id/index.html.md): 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()](https://php7explained.com/new-and-extended-functionality/language-features/get_mangled_object_vars/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/gettype-and-resources/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/custom-object-serialization/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/is_object-and-incomplete-classes/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/null-coalesce-operator/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/null-coalescing-assignment-operator/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/combined-comparison-operator/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/weak-references/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/numeric-literal-separator/index.html.md): 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](https://php7explained.com/new-and-extended-functionality/language-features/trailing-commas-in-function-and-method-calls/index.html.md): 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.

---

Previous: [Changed Error Messages](https://php7explained.com/new-and-extended-functionality/type-system/changed-error-messages/index.html.md) | Next: [Preloading](https://php7explained.com/new-and-extended-functionality/language-features/preloading/index.html.md)
