What’s New in PHP 8.4? Explore Enhanced String Functions, HTML5 DOM, and More

PHP 8.4, slated for a November 2024 release, introduces enhanced multibyte string functions, HTML5‑aware DOM extensions, stronger password hashing, property hooks, parenthesis‑free method calls, JIT configuration changes, and deprecates implicit nullable types, offering developers a more powerful and secure platform.

21CTO
21CTO
21CTO
What’s New in PHP 8.4? Explore Enhanced String Functions, HTML5 DOM, and More

PHP 8.4 Release Overview

PHP 8.4 is scheduled for release on 21 November 2024 and brings a suite of enhancements aimed at smoother, safer, and more efficient development.

Enhanced Multibyte String Functions

The update adds functions such as mb_ucfirst, mb_lcfirst, mb_trim, mb_ltrim and mb_rtrim to improve handling of multibyte strings.

echo mb_ucfirst("translation"); // outputs: "Translation"

DOM Extension Supports HTML5

The DOM extension now includes HTML5 parsing and serialization via the new DOM\HTMLDocument class.

use DOM\HTMLDocument;
$htmlDocument = HTMLDocument::createFromString('<!DOCTYPE html><html><body>Hello, HTML5!</body></html>');

Stronger Password Hashing

The default bcrypt cost is increased from 10 to 12, raising the computational effort required to crack hashes.

Property Hooks

Inspired by Kotlin and C#, property hooks let developers override default get and set behavior for class properties, reducing boilerplate getters and setters.

class BookViewModel
{
    public function __construct(
        private array $authors,
    ) {}

    public string $credits {
        get {
            return implode(', ', array_map(
                fn (Author $author) => $author->name,
                $this->authors,
            ));
        }
    }

    public Author $mainAuthor {
        set (Author $mainAuthor) {
            $this->authors[] = $mainAuthor;
            $this->mainAuthor = $mainAuthor;
        }
        get => $this->mainAuthor;
    }
}

No‑Parentheses Method Calls

Method calls can now be written without surrounding parentheses, and the same syntax works for property, static method, and constant access.

$name = new ReflectionClass($objectOrClass)->getShortName();

JIT Configuration Changes

JIT can be disabled with opcache.jit=disable. To enable JIT, both opcache.jit and opcache.jit_buffer_size must be set, e.g., opcache.jit=64m. Additional performance and memory improvements are also included.

Deprecation of Implicit Nullable Types

Implicitly nullable parameters like function save(Book $book = null) {} are deprecated; the explicit nullable type ?Book must be used.

function save(?Book $book = null) {}

Conclusion

PHP 8.4 delivers significant upgrades—from multibyte string handling and HTML5 DOM support to stronger password hashing and property hooks—making PHP development more powerful and secure. Teams should start planning integration before the official launch.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backend DevelopmentPHPDOMProperty Hookspassword hashing8.4multibyte strings
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.