DeveloperJoy Logo DeveloperJoy

What's new on PHP 8.4

May 25, 2024
What's new on PHP 8.4

The wait is almost over, and PHP 8.4 is just around the corner! Let's dive into the exciting new features and changes that have been announced so far.

Mark Your Calendars: PHP 8.4 Release Date

Get ready to upgrade on November 21, 2024! Before the official release, PHP 8.4 will go through a 6-month pre-release phase, featuring Alphas, Betas, Release Candidates, and finally, the official launch.


Property Hooks

Inspired by languages like Kotlin, C#, and Swift, property hooks are set to revolutionize the way you code. With two syntax variants, reminiscent of short and multi-line closures, you'll be able to:

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;

Property hooks will simplify your code by eliminating boilerplate property getters and setters, allowing you to define access and updates with ease.

Also, you can define property hooks in interfaces so you can make sure that each implementation follow the same rules.

interface Named
    // Objects implementing this interface must have a readable
    // $fullName property.  That could be satisfied with a traditional
    // property or a property with a "get" hook.
    public string $fullName { get; }

Here you can find more info about Property Hooks in the official RFC page.

new Classes without Parentheses

Goodbye Unnecessary Parentheses. PHP 8.4 is bringing another game-changer to the table: no more wrapping new invocations in parentheses to chain methods! This means you can ditch the extra syntax and make your code more concise and readable.

Take a look at this example:

// Before PHP 8.4
$name = (new MyClass())->execute();

// With PHP 8.4
$name = new MyClass()->execute();

Not only does this update simplify your code, but it also works seamlessly with properties, static methods, and constants.

new MyClass()::CONSTANT,        // string(8)  "constant"
new MyClass()::$staticProperty, // string(14) "staticProperty"
new MyClass()::staticMethod(),  // string(12) "staticMethod"
new MyClass()->property,        // string(8)  "property"
new MyClass()->method(),        // string(6)  "method"
new MyClass()(),                // string(8)  "__invoke"

This small but significant change will make a huge difference in your coding experience.

New DOM HTML5 parser

In PHP we already have the \DOMDocument class. This was used to parse HTML code but it was not fully compatible with HTML5 code.

Now, the new \Dom\HTMLDocument is fully compatible with HTML5 and the new default way to go.

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

The previous class still available, but I think there is no reason to still using it.

← Go back to the blog

Work with me

Do you own a company or need help with your Laravel project? I can help you with that. Check the plans and let me know if you have any questions.

Get 1 month free with yearly plan during checkout.

Technical Advisor

$ 3 ,995


What's included:

  • Lead your team to a better code architecture, testing mentality, clean code, and more.
  • Lead knowledge-sharing sessions depending on current company status and requirements.
  • Help with product and technical decisions.
  • Pause or cancel anytime.

Integrated Senior Developer

$ 5 ,995


Not available

What's included:

  • Includes all Technical Advisor services.
  • Engages as a team member in daily tasks.
  • Participates actively in day-to-day development.
  • Direct communication:
    Slack, and meetings included.
  • Pause or cancel anytime.

Want to talk first?

Ok, just book a call now.