A featured image with a laptop, displaying the official PHP.net logo of PHP 8.4, and the signature PHP elephant icon.

PHP 8.4 Highlights: What is New, Features and Improvements Explained

Packed with powerful features and enhancements, the latest PHP 8.4 version promises to make coding more efficient and flexible.

Released officially in late November 2024, at SiteGround, PHP 8.4 has been around in beta since August 2024, when we were among the first companies to make it available for testing on all our servers.

Since then, we’ve seen that it is becoming more and more popular. Over 6000 website owners hosting with SiteGround have already tried it on their website.

If you’re wondering whether you should make the switch and what’s the fuss about, keep reading as we’re covering all you need to know about PHP 8.4, from its standout features to practical tips who will benefit from it the most. Let’s dive in!

PHP 8.4 Key Takeaways

PHP 8.4 marks a significant update in PHP’s lifecycle, introducing bug fixes, features and enhancements that optimize performance and development.

Features like enhanced property handling, new helper functions, and advanced database tools simplify coding and improve efficiency.

Using the latest versions also helps protect against vulnerabilities in the long-run.

However, as a website owner, you have to be careful – the most recent versions may not be compatible with your website. We recommend testing it on a website staging copy first.

Release Timeline and SiteGround

PHP 8.4 (Beta 3) was released on August 15th, 2024. SiteGround introduced early access to it on August 20th, 2024, so our clients could use it for testing as early as possible.

PHP 8.4’s general availability release (GA) was on November 21, 2024. SiteGround added the official version to our servers on November 26th, 2024, just five days after it was announced.

What is New in PHP 8.4?

PHP 8.4 introduces multiple new features that can be categorized into syntax enhancement, library and API improvements, and better array manipulation.

1. Syntax and Language Enhancements

1.1. Property Hooks

In PHP versions prior to 8.4, managing property access and modification typically involved defining explicit getter and setter methods within a class.

This approach, while functional, often led to more verbose code and separated the property’s behavior from its declaration.

class User {
    private string $firstName;
    private string $lastName;

    public function __construct(string $firstName, string $lastName) {
        $this->firstName = $firstName;
        $this->lastName = $lastName;
    }

    public function getFullName(): string {
        return $this->firstName . ' ' . $this->lastName;
    }

    public function setFullName(string $fullName): void {
        [$this->firstName, $this->lastName] = explode(' ', $fullName, 2);
    }
}

$user = new User('John', 'Doe');
echo $user->getFullName(); // Outputs: John Doe
$user->setFullName('Jane Smith');
echo $user->getFullName(); // Outputs: Jane Smith

In this example, the getFullName and setFullName methods are used to access and modify the user’s full name.

With the introduction of property hooks in PHP 8.4, developers can now define custom behavior for property access (get) and modification (set) directly within the property declaration.

This feature streamlines the code by embedding the logic within the property itself.

Using Property Hooks in PHP 8.4:

class User {
    private string $firstName;
    private string $lastName;

    public function __construct(string $firstName, string $lastName) {
        $this->firstName = $firstName;
        $this->lastName = $lastName;
    }

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

$user = new User('John', 'Doe');
echo $user->fullName; // Outputs: John Doe
$user->fullName = 'Jane Smith';
echo $user->fullName; // Outputs: Jane Smith 

In this updated example, the fullName property utilizes property hooks to define the get and set behaviors directly within its declaration.

This approach reduces the need for separate methods and keeps the property’s logic encapsulated within its definition.

For a comprehensive understanding and additional examples, refer to the official PHP manual on property hooks.

1.2. Asymmetric Visibility

In PHP 8.4, asymmetric visibility allows developers to define separate access levels for reading and writing class properties.

A screenshot of a code snippet from the official PHP.net documentation, highlighting how new asymmetric visibility enhancements change coding practices.

The visibility declaration public private(set) is used to allow public access for reading but restrict private access for setting the value. This allows the property to be readable from outside the class but only modifiable within the class.

1.3. #[\Deprecated] Attribute

In PHP 8.4, the #[\Deprecated] attribute was introduced to mark classes, methods, functions, or properties as deprecated.

This serves as a formal indication that the marked element is discouraged for use and may be removed in future versions.

Utilizing this attribute enhances code clarity and assists developers in identifying and transitioning away from deprecated features.

1.4. New MyClass()->method() without Parentheses

In PHP 8.4, the syntax for invoking a method directly after creating a new instance of a class has been enhanced. Previously, you would instantiate a class and then call a method on that instance in two separate steps:

$instance = new MyClass();

$instance->method();

With PHP 8.4, you can now chain the method call directly to the instantiation, eliminating the need for parentheses:

new MyClass->method();

This streamlined syntax improves code readability and reduces verbosity.

2. Library and API Improvements

2.1. Object API for BCMath

In PHP 8.4, the BCMath extension introduces the BcMath\Number class, providing an object-oriented approach to arbitrary precision arithmetic.

A screenshot of a code snippet from the official PHP.net documentation, highlighting how to implement an object-oriented approach to arbitrary precision arithmetic using the new BcMath\Number class.

This enhancement allows for more intuitive and readable code when performing decimal calculations.

2.2. New ext-dom Features with Enhanced HTML5 Support

The ext-dom extension has been enhanced to provide robust, standards-compliant support for parsing and manipulating HTML5 documents.

This improvement addresses long-standing issues and introduces new features that streamline working with HTML5 content.

Key Enhancements:

  1. Introduction of Dom\HTMLDocument Class:
    • A new class, Dom\HTMLDocument, has been added to the Dom namespace. This class offers a modern, object-oriented interface for handling HTML5 documents, ensuring better integration and usability.
  2. Improved Parsing and Serialization:
    • The new API provides accurate parsing and serialization of HTML5 documents, resolving previous compliance issues. This ensures that HTML5 content is handled correctly, facilitating more reliable document manipulation.
  3. Enhanced Functionality:
    • Several new functions have been introduced to simplify common tasks, such as querying elements using CSS selectors and traversing the DOM. These additions make it more convenient to work with HTML5 documents.

2.3. PDO Driver-Specific Subclasses

In PHP 8.4, the introduction of PDO driver-specific subclasses enhances the flexibility and functionality of the PDO (PHP Data Objects) extension. This enhancement allows developers to access database features such as driver specific sql parsers, that were previously inaccessible through the generic PDO class.

Key Features:

  • Access to Driver-Specific Methods: Each PDO driver now has its own subclass, enabling access to methods unique to that database system. For example, the Pdo\Sqlite subclass provides methods like createFunction(), which are specific to SQLite.
  • Improved Code Clarity: By utilizing these subclasses, code becomes more readable and maintainable, as database-specific functionalities are encapsulated within their respective classes.
// Using PDO::connect() to instantiate the driver-specific subclass

$pdo = PDO::connect('sqlite:/path/to/database.db');

// Using the driver-specific method

$pdo->createFunction('my_function', function($value) {

return strtoupper($value);

});

In this example, PDO::connect() returns an instance of Pdo\Sqlite, allowing access to SQLite-specific methods like createFunction().

Backward Compatibility:

This enhancement maintains backward compatibility. Existing code using the generic PDO class continues to function as before. Developers can choose to utilize the driver-specific subclasses when they need access to database-specific features.

2.4. Standard Library Updates

Beyond major library and API changes, PHP 8.4 refines its standard library with helpful new utility functions and subtle enhancements.

For example, developers now have access to fpow() for floating-point exponentiation, new lazy objects and new methods for managing HTTP response headers.

Additionally, the DateTime library receives precision-focused updates, which improves how PHP handles time-related tasks. These updates, though smaller in scope, contribute to a smoother and more efficient development experience.

3. New Helper Functions

PHP 8.4 introduces new array functions, providing more versatile and efficient ways to manipulate arrays.

  • array_findSearches an array for the first element that satisfies a given condition.
  • array_find_keyFinds the key of the first element in an array that meets a specified condition.
  • array_anyChecks if any element in an array satisfies a given condition.
  • array_allDetermines if all elements in an array meet a specified condition.
$numbers = [1, 2, 3, 4, 5];

// Find the first even number
$firstEven = array_find($numbers, fn($n) => $n % 2 === 0);
echo $firstEven; // Outputs: 2

// Find the key of the first number greater than 3
$key = array_find_key($numbers, fn($n) => $n > 3);
echo $key; // Outputs: 3

// Check if any number is greater than 4
$anyGreaterThanFour = array_any($numbers, fn($n) => $n > 4);
var_dump($anyGreaterThanFour); // Outputs: bool(true)

// Check if all numbers are positive
$allPositive = array_all($numbers, fn($n) => $n > 0);
var_dump($allPositive); // Outputs: bool(true)

These additions streamline array operations, enhance code clarity, and reduce the need for verbose loops.

PHP 8.4 Deprecations

With each new PHP release, some features are marked as deprecated to pave the way for better alternatives. Deprecations help PHP to evolve while giving developers time to adjust their code.

One notable deprecation in PHP 8.4 is the removal of dynamic properties on standard objects, a feature long used for quick, ad-hoc property assignments. Another example is the deprecation of implicit nullable types.

Developers are now encouraged to use typed properties or magic methods like __get and __set for better performance and clarity.

For a complete list of deprecated features, you can check out the official documentation released by the php team.

1. Backward incompatible changes

There is a difference between deprecations and backward incompatible changes. With each release, there are also changes that fully break how certain syntax and code functions work.

For a full list of backward incompatible updates, refer to the official PHP documentation.

This means you have to be extra careful about switching to a more recent version. Often, if you are using 3rd party software, you may run into issues since it takes time for developers to update their products so they are compatible with the most recent PHP version.

This is why you should use a staging environment to test if the newest release breaks parts of your website. This is especially important if you are currently running a version older than 8.0.

We’ll show you how you can safely do this using SiteGround’s tools later in the article.

If you manage a website, it’s a good time to audit your code for deprecated features. Addressing these changes now can save you headaches when future PHP versions remove them entirely.

You can request a PHP compatibility check as part of our Expert Care services, so the review and upgrade can be handled professionally by our technicians.

2. Version Support

PHP 8.4 will receive active support for two years, followed by two years of critical security updates. You can review the official PHP documentation for the exact cutoff dates.

If you are using a deprecated version of PHP, we strongly recommend updating to the most recent stable version for improved security and performance.

How to Upgrade to PHP 8.4?

For most users, we recommend staying on Managed PHP to avoid any complications and breaking your production website. If you are technically savvy, and wish to test how your site runs on 8.4, keep reading so you can learn how to do it safely.

1. SiteGround’s Managed PHP

By default, all SiteGround clients are set to our Managed PHP service, which means that we will automatically update your PHP version once a newer stable version is available.

This is recommended for most users that are not tech-savvy, because the newest versions may introduce a conflict in your application due to a plugin or theme incompatibility.

We carefully evaluate each new PHP release and perform tests for compatibility with the most widely used applications on our platform.

As of February 2025, SiteGround’s default Managed PHP version on our servers is 8.2.

We recommend this version as the most widely-compatibale latest release. Before upgrading our default PHP version, we always make sure we have enough usage data to ensure the security, stability, and performance for the majority of websites on our platform.

That’s why we allow some time before switching our default version to each new release, even though the latter are available for testing on our servers almost immediately after going out.

Advanced users can manually switch to PHP 8.4 at any time via Site Tools.

2. Compatibility

As we mentioned, all newest PHP releases can cause errors on your website, so it’s always recommended to test the most recent versions in a staging environment first.

We offer a hassle-free, one-click tool that allows you to easily create a clone of your WordPress site, which you can use to check for any plugin or theme conflicts before upgrading your main website.

A screenshot of SiteGround's Site Tools dashboard page, where you can create a Staging copy of your WordPress site.

Once you’ve created a staging copy, follow the steps below if you wish to to switch it to PHP 8.4 and test how it works on your site.

3. Test PHP 8.4.

Most providers offer a PHP management tool to switch between different versions for your website. To upgrade to 8.4 manually on SiteGround, go to your Site Tools dashboard > Devs > PHP manager:

A screenshot of SiteGround's Site Tools dashboard PHP manager, where you can change the PHP settings of your sites.

Switch to the Staging Sites tab:

A screenshot of SiteGround's Site Tools dashboard PHP manager, where you can change the PHP settings of a staging site.

Click the Edit button under Actions, switch from Managed PHP to Change PHP version manually, and select 8.4.3.

A screenshot of SiteGround's Site Tools dashboard menu, where you change the PHP version of a website, with a dropdown showing available versions ranging from 8.0 to 8.4.

It’s that simple! The next step is to check if the website works as expected. If some functionality breaks, you would need to investigate further.

Maybe a plugin or the theme that you are using is not fully compatible with the newest version yet. Or, there could be some custom PHP code in your site that needs to be revamped.

In such cases, it’s best to remain on our Managed PHP version and wait until these issues are addressed, before upgrading your main website to the latest PHP release.

4. Ultrafast PHP

SiteGround has a well-established reputation for focusing on performance optimization. This is why our team has developed a custom rendition of PHP that increases website performance by up to 30%.

It is exclusively available to our users on GrowBig plans (and above) and is fully compatible with PHP 8.4. If you wish to take advantage of it, check out our Managed Hosting solutions and sign up today to boost your website speed!

A promotional banner listing SiteGround's unique speed hosting features.

PHP 8.4: Recap and Next Steps

PHP 8.4 is a useful improvement for developers and website owners alike. With its streamlined syntax, improved APIs, and new features, it simplifies coding while boosting website performance and reliability.

Staying up to date with PHP versions is essential for maintaining a fast and reliable online presence. Upgrades should be handled carefully, to ensure a smooth transition and a seamless experience for your visitors.

This is why it is important to use a hosting provider that is up to speed with the latest technologies and offers the necessary tools to safely manage your website.

At SiteGround, we make upgrading hassle-free. With our Managed PHP and Ultrafast PHP services, you can enjoy peak performance and seamless updates.

Ready to experience the best PHP 8.4 has to offer? Sign-up for our Managed Hosting plans today and future-proof your website!

Aleksandar Kolev

Technical Content Writer

Aleksandar has been with SiteGround since 2019, always striving to bring both a keen analytical mindset and a creative touch to his work. As a technical content writer, he is dedicated to making complex topics accessible and engaging. Outside of work, Aleksandar enjoys a minimalist, nature-focused lifestyle and has a passion for music and performing. His ongoing interest in yoga, Tai-Chi, and meditation adds to his balanced approach to both life and work.

Speed

Start discussion