The latest version of PHP, 8.4, brings exciting innovations, including property hooks, asymmetric visibility, and extended array functions. These enhancements aim to make programming more efficient and flexible.
Property Hooks: Precise control over properties
With the introduction of property hooks, PHP 8.4 enables targeted control of class property behavior. Developers can define so-called get and set hooks that execute user-defined logic when accessing or modifying properties. This reduces the need for extensive getter and setter methods. An additional improvement is the ability to define properties in interfaces. This facilitates the typing and specification of operations, making the structure of the code clearer.
Asymmetric visibility: Flexible access
Another important feature is asymmetric visibility. This allows read and write permissions for properties to be configured differently. For example, developers can make a property publicly readable but only modifiable internally. This feature increases security and flexibility when using classes.
Example:
class Example {
public protected(set) string $name;
public function __construct(string $name) {
$this->name = $name;
}
}
Advanced array functions
PHP 8.4 introduces several new array functions designed to make working with arrays easier:
- array_find: Returns the first element that satisfies a given callback.
- array_find_key: Returns the key of the first matching element.
- array_any: Checks whether at least one element meets the conditions.
- array_all: Verifies whether all elements satisfy the conditions.
These functions save time because they provide frequently used logic directly.
Simplified syntax for instantiation
Another focus of version 8.4 is on improving code readability. When directly instantiating a class followed by a method call, the parentheses can be omitted. This makes the code more compact and clearer.
Before:
var_dump((new PhpVersion())->getVersion());
Now:
var_dump(new PhpVersion()->getVersion());
HTML5 support and just-in-time compilation
Support for HTML5 parsing has been revised in PHP 8.4. A new parsing library offers full support for HTML5 and significantly improves working with DOM structures.
In addition, the just-in-time compilation process (JIT) has been optimized. Although JIT remains disabled by default, new configuration options allow for more efficient customization.
Further improvements
In addition to the main features, there are numerous other updates:
- New HTTP verbs for $_POST and $_FILES.
- Multibyte trim function mb_trim().
- Revised rounding modes for round().
- Improvements in the DOM and XSL extensions.
- Support for lazy objects for proxy objects.
- Introduction of the #[Deprecated] attribute, which marks obsolete functions.
Conclusion: A versatile update for PHP
PHP 8.4 brings numerous innovations that improve both the flexibility and user-friendliness of the language. Whether it's optimized syntax, powerful new features, or greater control over classes, this version has the potential to significantly assist developers in creating modern and efficient web applications.
Developers who want to use the new features can find more information and the complete change log at php.net.






