What's New in PHP 8.1.0: Enums, Read‑only Properties, First‑class Callable Syntax, Fibers and More
PHP 8.1.0 introduces enums, read‑only properties, first‑class callable syntax, new initializers, intersection types, never return type, final class constants, explicit octal literals, fibers, string‑keyed array unpacking, and numerous performance optimizations, providing developers with richer language features and faster execution.
PHP 8.1.0 has been released, bringing a host of new language features and performance enhancements for backend developers.
Enums
Use enums instead of a set of constants and obtain immediate validation.
Read‑only Properties
Read‑only properties cannot be changed after initialization, making them suitable for modeling value objects and data transfer objects.
First‑class Callable Syntax
Now you can obtain references to any function directly.
New Initializers
Objects can now be used as default parameter values, static variables, global constants, and property parameters, enabling nested property usage.
Intersection Types
Intersection types allow a value to satisfy multiple type constraints simultaneously; mixing intersection and union types is currently unsupported.
Never Return Type
The never type indicates that a function or method never returns a value, typically because it throws an exception or terminates the script via die() , exit() , trigger_error() , etc.
Final Class Constants
Final class constants can be declared to prevent them from being overridden in subclasses.
Explicit Octal Number Syntax
Octal numbers can now be written with an explicit 0o prefix.
Fibers
Fibers provide a primitive for lightweight cooperative concurrency, allowing code blocks to be paused and resumed like generators, but from any point in the call stack. They do not provide parallelism themselves and still rely on an event loop, yet they simplify asynchronous code by removing boilerplate associated with promises or generator‑based coroutines.
Array Unpacking Support for String‑Keyed Arrays
PHP now allows the spread operator to unpack arrays with string keys, extending the previous integer‑key‑only support.
Performance Optimizations
PHP 8.1 includes several performance improvements, such as an ARM64 JIT backend, inheritance caching, faster class name resolution, timelib and ext/date enhancements, SPL filesystem iterator upgrades, serialization/deserialization speedups, internal function optimizations (e.g., get_declared_classes() , explode() , strtr() , strnatcmp() , dechex() ), and various JIT refinements.
For more details, see the official announcement at https://www.php.net/index.php .
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
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.