PHP 8.4 introduces property hooks, asymmetric visibility, the array_find function, and HTML5 parsing. Here is what these changes mean for your Laravel and Symfony projects.

7 min read · Published Mar 15, 2026

PHP
PHP 8.4 New Features Every Developer Should Know
by DevParagon Team 0 Comment

What Is New in PHP 8.4

PHP 8.4 is one of the most feature-rich releases in years. Property hooks alone change how we write value objects and DTOs, while asymmetric visibility finally solves the "public getter, private setter" boilerplate problem. These are not incremental improvements—they fundamentally change how PHP developers structure their classes.

Property Hooks

Property hooks let you define get and set logic directly on a property without writing separate methods. A $fullName property can compute its value from $firstName and $lastName on read, eliminating accessor methods while keeping the public API clean.

This is transformative for value objects and DTOs. Instead of cluttering classes with getters and setters, you define the behavior inline with the property declaration. The result is more concise, more readable code that still provides the encapsulation guarantees you need. Frameworks like Laravel are already exploring how property hooks can simplify model attribute casting and form request validation.

Property hooks also support virtual properties—properties that exist only as computed values with no backing storage. Define a get hook without a set hook and the property becomes read-only and computed. This replaces the common pattern of getFullNameAttribute() accessor methods with a cleaner syntax.

Asymmetric Visibility

Declare a property as public private(set) string $name to allow anyone to read it but only the class itself to write it. This removes the need for readonly properties in many cases and gives you finer-grained control over property access.

The practical impact is significant: you can create objects that are easy to consume from the outside (all properties are publicly readable) while maintaining strict control over mutation (only internal methods can modify state). This is particularly useful for domain objects where you want to expose data to views and serializers without allowing arbitrary modification.

New Array Functions

array_find(), array_find_key(), array_any(), and array_all() bring functional-style operations to native PHP. No more writing foreach loops just to check if any element matches a condition. These functions accept callbacks and operate on standard PHP arrays, integrating seamlessly with existing code.

array_find() returns the first element matching a callback, or null if none match. array_any() returns true if at least one element satisfies the condition. array_all() returns true only if every element passes. These are the array equivalents of collection methods that Laravel developers have used for years, now available without any framework dependency.

HTML5 Parsing with Dom\HTMLDocument

The new Dom\HTMLDocument class parses HTML5 correctly, replacing the legacy DOMDocument that mangled modern markup. If you scrape websites, process user-submitted HTML, or build content management systems, this is a significant improvement. The new parser handles void elements, template tags, and custom elements according to the HTML5 specification.

Lazy Objects

PHP 8.4 supports lazy object initialization natively via ReflectionClass::newLazyGhost() and newLazyProxy(). ORMs and dependency injection containers can delay object creation until the first property access, improving performance for complex object graphs. Doctrine and other ORMs that previously used complex proxy generation can now use native lazy loading, resulting in simpler and faster code.

Multibyte String Improvements

New mb_trim(), mb_ltrim(), and mb_rtrim() functions handle multibyte string trimming natively. Previously, developers had to use regex or custom functions to trim Unicode whitespace characters. These additions make PHP more robust for international applications where strings contain non-ASCII characters.

Upgrading Your Projects

Run your test suite on PHP 8.4, update your composer.json platform constraint, and start adopting new features incrementally. Property hooks and asymmetric visibility are backward-compatible additions—you can introduce them file by file without a big-bang migration. Use PHP CS Fixer or Rector to automate the adoption of new syntax where possible.

Conclusion

PHP 8.4 continues the language's transformation from a simple scripting language into a modern, expressive programming language. Property hooks reduce boilerplate, asymmetric visibility improves encapsulation, and native lazy objects simplify ORM implementations. Upgrade your projects, adopt the new features gradually, and enjoy writing cleaner PHP.

0 Comment

Leave A Reply

logo

Let's Talk About Your Project

Let's have a real conversation about your challenges. No obligation, just a 15-minute chat to see if we're a fit.

Your Project Deserves More Than a Form

Send Us Your Query