PHP 8.4 introduces some of the most significant language improvements in years. For Laravel developers, these features simplify common patterns, reduce boilerplate code, and improve application performance. Here is everything you need to know about PHP 8.4 and how to leverage it in your Laravel projects.
PHP 8.4 Release Highlights
PHP 8.4, released in November 2025, is now production-ready and widely adopted. The release focuses on developer experience improvements, performance optimizations, and new language constructs that make PHP code more expressive and maintainable. Laravel 11 and 12 both support PHP 8.4 fully, and many of the new features integrate beautifully with Laravel's existing patterns.
Property Hooks — Cleaner Eloquent Models
Property hooks are the headline feature of PHP 8.4. They allow you to define getter and setter logic directly on class properties, eliminating the need for separate accessor and mutator methods in many cases.
For Laravel developers, property hooks complement Eloquent accessors and casts. While Eloquent's built-in attribute casting remains ideal for database-related transformations, property hooks excel for computed properties, validation logic, and data formatting within service classes and value objects.
// PHP 8.4 Property Hooks
class UserProfile
{
public string $displayName {
get => $this->firstName . ' ' . $this->lastName;
}
public string $email {
set(string $value) => strtolower(trim($value));
}
public function __construct(
private string $firstName,
private string $lastName,
) {}
}
This eliminates the boilerplate of creating separate getter and setter methods while keeping the logic co-located with the property definition. The code is more readable, more maintainable, and immediately communicates the property's behavior to any developer reading the class.
Asymmetric Visibility — Better Encapsulation
Asymmetric visibility allows you to set different access levels for reading and writing a property. You can make a property publicly readable but only privately writable — a pattern that previously required a private property with a public getter method.
// PHP 8.4 Asymmetric Visibility
class Order
{
// Publicly readable, privately writable
public private(set) string $status = 'pending';
public private(set) float $total = 0.0;
public private(set) \DateTimeImmutable $createdAt;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
}
public function complete(): void
{
$this->status = 'completed';
}
}
In Laravel applications, asymmetric visibility is particularly useful for DTOs (Data Transfer Objects), value objects, and event classes where you want properties accessible externally but only modifiable through controlled methods. This pattern enforces better encapsulation without the verbosity of traditional getter/setter pairs.
New HTML5 Parser — DOM Improvements
PHP 8.4 introduces a modern HTML5-compliant DOM parser through the \Dom\HTMLDocument class. This replaces the legacy DOMDocument class, which was based on the outdated libxml2 HTML parser and frequently struggled with modern HTML5 markup.
For Laravel developers building web scrapers, email template generators, or HTML processing pipelines, this is a significant improvement. The new parser handles modern HTML5 elements, self-closing tags, and SVG content correctly, eliminating the workarounds and warning suppressions that DOMDocument required.
// PHP 8.4 HTML5 Parser
$doc = \Dom\HTMLDocument::createFromString($htmlContent);
$elements = $doc->querySelectorAll('.product-card');
foreach ($elements as $el) {
$title = $el->querySelector('h3')?->textContent;
$price = $el->querySelector('.price')?->textContent;
}
Performance Benchmarks: PHP 8.4 vs 8.3
PHP 8.4 delivers measurable performance improvements over PHP 8.3, particularly in JIT compilation and memory management. Real-world Laravel benchmarks show:
- Request throughput: 5-8% improvement in requests per second for typical Laravel applications.
- Memory usage: 3-5% reduction in peak memory consumption during complex operations.
- JIT compilation: Improved JIT performance for CPU-intensive operations like image processing and data transformation.
- Array operations: New array helper functions perform 10-15% faster than equivalent userland implementations.
While individual benchmark improvements appear modest, they compound across the thousands of operations in a typical Laravel request lifecycle. For high-traffic applications, the cumulative performance gain can meaningfully reduce server costs and improve response times.
Migration Guide for Laravel Projects
Upgrading a Laravel project to PHP 8.4 is generally straightforward, but follow this checklist to ensure a smooth transition:
Step 1: Review the PHP 8.4 migration guide for deprecated features and breaking changes. The most common issues are deprecated function signatures and changes to default parameter values.
Step 2: Update your composer.json to require PHP 8.4 and run composer update. Address any dependency conflicts — most major Laravel packages already support PHP 8.4.
Step 3: Run your test suite. PHPUnit and Pest both support PHP 8.4 fully. Fix any deprecation warnings that appear during test execution.
Step 4: Use PHPStan or Psalm at their highest analysis levels to catch type-related issues introduced by PHP 8.4's stricter type handling.
Step 5: Deploy to a staging environment and conduct thorough testing before updating production.
Using AI Tools to Auto-Upgrade PHP Code
AI coding assistants like Cursor and Rector can automate much of the PHP upgrade process. Rector provides automated refactoring rules that transform PHP 8.3 code patterns into PHP 8.4 equivalents — converting traditional getters/setters to property hooks, implementing asymmetric visibility where appropriate, and updating deprecated function calls.
Cursor can analyze your entire Laravel codebase and suggest opportunities to leverage PHP 8.4 features. Ask it to "identify all classes that would benefit from property hooks" or "find getter methods that could be replaced with asymmetric visibility" to systematically modernize your codebase.
"Every major PHP release makes Laravel development more enjoyable. PHP 8.4's property hooks and asymmetric visibility are game-changers for clean, expressive code."
Conclusion
PHP 8.4 represents a significant step forward for the language, with features that directly benefit Laravel developers. Property hooks reduce boilerplate, asymmetric visibility improves encapsulation, and the new HTML5 parser modernizes DOM handling. Combined with meaningful performance improvements, PHP 8.4 is a compelling upgrade for any Laravel project.
