PHP 8.4 introduces a range of features aimed at improving performance, code clarity, and developer efficiency. Here are the highlights:
- Property Hooks: Inspired by languages like Kotlin and C#, property hooks enable custom behavior for getting and setting property values directly on class properties, reducing the need for explicit getter and setter methods.
- Enhanced JIT Compiler: The Just-In-Time (JIT) engine now uses Intermediate Representation (IR), leading to better optimization, faster execution, and support for newer hardware platforms like RISC-V.
- Simplified
new
Syntax: Methods, properties, and constants can now be chained directly after instantiating a class without additional parentheses, making code more concise. - Asymmetric Visibility: PHP now supports different visibility levels for reading and writing properties, such as allowing public reads but restricting writes to private or protected contexts.
- New Array Functions: Functions like
array_find()
,array_any()
, andarray_all()
simplify common operations on arrays, such as searching for elements or checking conditions. - HTML5 Support: A new
\Dom\HTMLDocument
class replaces\DOMDocument
for better compatibility with modern HTML5 structures. - Exit and Die as Functions: These are now fully recognized as proper functions, making them consistent with the rest of the language.
- Lazy Objects: Native support for lazy initialization reduces resource usage by deferring object creation until they are accessed.
- Deprecated Implicit Nullable Types: Variables with default
null
values must now be explicitly marked nullable using?
, improving code clarity and preparing for stricter rules in future versions.
These changes make PHP 8.4 a powerful update, particularly for developers working on high-performance or modern web applications.