testing24358bool(false)

PHP 8.4 Release – Experience New Features & Enhancements

PHP 8.4 Release

PHP is the mastermind behind various web applications. Finally, the long wait is over. PHP 8.4 has been officially released. Users can experience new features and improvements like property hooks, array find functions, and more. From the developers’ perspective, they can benefit from more improved and impactful features, allowing them to make their web development processes results-driven.

This blog post will explain the PHP 8.4 release, what’s new in it, and why this release is crucial for improving web development in the future.

PHP 8.4 Release (New Features and Improvements)

As mentioned, the PHP 8.4 release date is November 23, 2024. It is the latest version compared to previous PHP versions.

PHP 8.4 will delight users with numerous impactful features and enhancements. For instance, they can smartly utilize new array functions, such as:

  • ‘array_ find()’
  • ‘array_find_key()’
  • ‘array_any()’
  • ‘array_all()’

Besides, there are other incredible PHP 8.4 features which will grab users’ attention from the word go, including:

  • Property Hooks
  • Asymmetric Visibility
  • MyClass()->method() Without Parentheses
  • JIT Changes
  • HTML5 Support
  • Other PHP 8.4 features to watch

Property Hooks

Properties in PHP objects have offered various benefits to PHP developers. For example, they help them implement value validations. For that reason, property types starting in PHP 7 have greatly helped this.

Still, the fact that validation must, by necessity, happen via a method has led to many boilerplates in the form of getters and setters or abuse of the __get and __set magic methods.

In reality, read-only properties in PHP 8 resolve numerous issues for developers. They can guard values through the constructor and still offer fully typed properties for direct access.

Property Hooks also offers a robust feature for working with PHP class properties. Properties can optionally explain one or more hooks, currently limited to “get” and “set,” enabling you to hook into the property’s lifecycle. Here is an example from the RFC:

class User implements Named
{
    private bool $isModified = false;
    public function __construct(private string $first, private string $last) {}
    public string $fullName {
        // Override the "read" action with arbitrary logic.
        get => $this->first . " " . $this->last;
        // Override the "write" action with arbitrary logic.
        set {
            [$this->first, $this->last] = explode(' ', $value, 2);
            $this->isModified = true;
        }
    }
}

Asymmetric Visibility

Asymmetric visibility is an innovative feature that helps developers explain differing visibility for various operations on a property. This allows them to smartly gain control over the visibility of class members, such as properties and methods.

For instance, you can suggest that you wish to allow public read access to a property, however, only allow modifications to it internally:

public private(set) string $bar = ‘baz’;

Asymmetric visibility works in parallel with the changes presented with property hooks, including the ability to describe visibility in interfaces.

MyClass()->method() Without Parentheses

A common practice in PHP is instantiating a class instance and accessing a method or property without delay. Here is the example below:

$request = (new Request())->withMethod(‘GET’)->withUri(‘/hello-world’);

We must wrap the class in parentheses when instantiating it, which is the PHP engine’s requirement. Through PHP 8.4, users can omit such parentheses, offering a more user-friendly usage:

$request = new Request()->withMethod(‘GET’)->withUri(‘/hello-world’);

 JIT Changes

PHP 8.4 has changed the way the JIT is activated. Users had to set opcache.jit_buffer_size to 0 to deactivate the JIT previously. However, you can deactivate it as described below:

opcache.jit=disable

opcache.jit_buffer_size=64m

This change will affect users if they had specified a opcache.jit_buffer_size but did not specify opcache.jit. In this situation, users will need to incorporate opcache.jit=tracing to activate the JIT again. Besides, users will witness improvements to the JIT, making it run smoothly and fastly.

HTML5 Support

PHP 8.4 includes a \Dom\HTMLDocument class that can parse HTML code efficiently. The outdated \DOMDocument class is still accessible for backward compatibility.

$doc = \Dom\HTMLDocument::createFromString($contents);

For developers who parse or build HTML using the DOM extension, this release will provide various innovative yet results-driven features and robust support for HTML5.

PHP 8.4 Deprecations

With PHP 8.4 new features and enhancements aside, a few deprecations will occur. These deprecations are implicit nullable types and deprecation of GET/POST sessions.

Implicit Nullable Types

Previously, a typed variable with a default null value in PHP could have been made nullable automatically:

function foo(T1 $a, T2 $b = null, T3 $c) {}

When nullable types were included, this signature could have been explicitly obtained:

function bar(T1 $a, ?T2 $b = null, T3 $c) {}

Or through a union type:

function test(T1 $a, T2|null $b = null, T3 $c) {}

This implicit declaration worked without fuss previously. However, it has now been deprecated in PHP 8.4.

Deprecation of GET/POST Sessions

Web applications track user states utilizing cookies. In PHP, web applications perform this action through GET and POST parameters. For this purpose, users must deactivate the “session.use_only_cookies” setting, utilizing the features implemented in browsers before cookies.

In this scenario, a mechanism known as “session. use_trans_side” is enabled to help identify a session token in any user’s cookies or POST or GET parameters. “session.use_only_cookies” is activated by default, and “session.use_trans_sid” is deactivated. PHP 8.4 will alert a deprecation warning if either value is toggled differently.

PHP 8.4 Other Impressive Features

Here are other impressive features users will benefit from, including:

  • $_POST and $_FILES now support additional HTTP verbs.
  • Multibyte trim functions: mb_trim(), mb_ltrim(), and mb_rtrim().
  • New, more precise, rounding modes for the round() function.
  • Driver-specific PDO subclasses to allow access to driver-specific features.
  • Improved callbacks for DOM and XSL, enabling closures, first-class callables, and instance methods.
  • The addition of Lazy Object support provides low-level features for generating ghost objects, proxies, and more; frameworks and ORMs will generally consume these for use with dependency injection containers and object hydration.
  • A new engine attribute, #[Deprecated], for marking deprecated functionality.
  • Several improvements to the BCMath, GMP, and DOM extensions.

PHP 8.4 Release Date Timeline (Snapshot)

As you know, the PHP 8.4 release date is 21 Nov 2024. For user’s ease, here is the PHP 8.4 release timeline:

Release DateMilestone
July 04, 2024Alpha Release 1
July 18, 2024Alpha Release 2
August 01, 2024Alpha Release 3 (Skipped)
August 1, 2024Alpha Release 4
August 13, 2024Feature Freeze
August 15, 2024Beta Release 1 (Skipped)
August 15, 2024Beta Release 2 (Skipped)
August 15, 2024Beta Release 3
August 29, 2024Beta Release 4
September 12, 2024Beta Release 5
September 26, 2024Release Candidate 1
October 10, 2024Release Candidate 2
October 24, 2024Release Candidate 3
November 7, 2024Release Candidate 4
November 23, 2024General Availability Release

What Can You Expect After PHP 8.4?

With the release of PHP 8.4, development for PHP 8.5 is already underway. The official release date for PHP 8.5 has been announced and is scheduled for November 25, 2025.

Wrapping Up

We hope you liked our comprehensive blog post describing the PHP 8.4 release, its new and impactful features, and improvements. The upcoming version signifies the importance of this popular programming language.

PHP 8.4 illuminates the continuous adaptation and growth of the dynamic web development landscape. Therefore, users must be smart enough to experience exciting features and improvements in the forthcoming version.

Developers can utilize PHP 8.4’s capabilities to take their web application development game to unprecedented heights. In addition, PHP 8.4 demonstrates its dedication to performance, output, and, most importantly, security in terms of profitability.

Share This Article