Skip to main content
Development 2 min read 213 views

PHP 8.4 Brings Property Hooks and Asymmetric Visibility

PHP 8.4, released November 21, 2024, introduces property hooks for getter/setter logic, asymmetric visibility, and a new HTML5-compliant DOM API.

TD

TechDrop Editorial

Share:

PHP 8.4 was released on November 21, 2024, introducing property hooks, asymmetric visibility, and a new HTML5-compliant DOM API. This release received the highest number of RFCs since PHP 8.0, with 36 accepted proposals.

Property Hooks

The most significant addition is property hooks, allowing custom logic when getting or setting property values without explicit getter/setter methods:

class User {
    public string $fullName {
        get => $this->firstName . ' ' . $this->lastName;
        set => [$this->firstName, $this->lastName] = explode(' ', $value, 2);
    }
}

This eliminates boilerplate while maintaining the clean public property syntax.

Asymmetric Visibility

Properties can now have different visibility for reading and writing:

class BankAccount {
    public private(set) float $balance = 0.0;
}

The $balance property can be read publicly but only modified within the class.

New DOM API with HTML5 Support

PHP 8.4 introduces Dom\HTMLDocument, leveraging the Lexbor parser for spec-compliant HTML5 parsing. This fixes long-standing issues with the old DOM extension's handling of modern HTML.

New Array Functions

Four new array functions simplify common operations:

  • array_find() - Find first element matching a callback
  • array_find_key() - Find key of first matching element
  • array_any() - Check if any element matches
  • array_all() - Check if all elements match

Support Lifecycle

PHP 8.4 will receive bug fixes until December 2026 and security fixes until December 2028, making it a solid choice for new projects.

Tags: #Php

Related Articles