DEV Community

Cover image for PHP 8.4: What to Expect, What’s New, and Why It’s a Big Deal for Developers
HichemTech
HichemTech

Posted on

PHP 8.4: What to Expect, What’s New, and Why It’s a Big Deal for Developers

Surprise! PHP 8.4 was supposed to land on November 21, 2024, but the PHP team decided to treat us early. PHP 8.4.0 officially dropped on November 19, and, as if that wasn’t enough, PHP 8.4.1 followed the next day on November 20. Talk about efficiency! Let’s dive into what’s new, why it’s great, and why developers everywhere should be excited about this release.


What’s New and Why It Matters

1. Property Hooks: Your New Favorite Feature

PHP 8.4 introduces Property Hooks, making getters and setters way more elegant. Now, you can define custom behavior for accessing and modifying class properties without endless boilerplate code.

Example:

class MagicClass {
    private array $data = [];

    public function __get($key) {
        return $this->data[$key] ?? null;
    }

    public function __set($key, $value) {
        $this->data[$key] = $value;
    }
}

$obj = new MagicClass();
$obj->name = "PHP";
echo $obj->name; // Outputs: PHP
Enter fullscreen mode Exit fullscreen mode

Less typing, more magic. Who doesn’t love that?


2. Asymmetric Visibility: Read, but Don’t Touch

With asymmetric visibility, you can now have separate access levels for getters and setters. For example, let the public read a property but keep write access private.

Example:

class ReadOnlyProperty {
    public string $data get;
    private string $data set;
}
Enter fullscreen mode Exit fullscreen mode

It’s like putting cookies on the table but keeping the jar lid locked. Everyone’s happy.


3. Method Chaining Without Parentheses

This one’s for all of us who’ve cursed extra parentheses in method chains. PHP 8.4 lets you chain methods directly on a newly instantiated object.

Example:

$result = new MyClass()->firstMethod()->secondMethod();
Enter fullscreen mode Exit fullscreen mode

No (new MyClass())-> nonsense. It’s clean, it’s readable, and it saves you precious keystrokes.


4. New Array Functions: Finally!

PHP 8.4 rolls out some much-needed array utilities like array_find() and array_find_key() to simplify everyday operations.

Example:

$numbers = [1, 2, 3, 4];
$found = array_find($numbers, fn($n) => $n > 2);

echo $found; // Outputs: 3
Enter fullscreen mode Exit fullscreen mode

These functions make arrays friendlier to work with, sparing you from the horrors of convoluted loops.


Under-the-Hood Improvements

  • HTML5 Support: The new \Dom\HTMLDocument class enables proper parsing of HTML5, perfect for modern web development.
  • Multibyte String Functions: New helpers like mb_ucfirst() make working with non-Latin scripts much easier.
  • Null Clarity: Implicit nullable parameters are deprecated, forcing clearer, better-defined function signatures.

Why PHP 8.4 Deserves the Hype

This release isn’t just about new features — it’s about making PHP more modern, efficient, and developer-friendly. Whether you’re a framework fanatic like Laravel (I’m a fan of Laravel 🤫), a WordPress wizard, or just tinkering with APIs, there’s something in PHP 8.4 for you.


Why the Early Release?

Who knows? Maybe the PHP team was just as excited as we are. Or maybe they wanted to give us a couple of extra days to play with the new features before the weekend 😁. Either way, it’s here, and it’s awesome.


What’s Next?

Make sure your codebase is ready for PHP 8.4. Check the release notes, test your apps, and enjoy the ride. Oh, and don’t forget to treat yourself to a coffee for upgrading early — you’ve earned it , oh well.. WE’ve earned it 😂.

PHP 8.4 is a game-changer. Dive in and discover what makes this version worth celebrating!

Top comments (2)

Collapse
 
xwero profile image
david duymelinck

Am I missing something? This is not on the PHP website.

Collapse
 
__7d22403a profile image
Constantine Beloglazov

When release? i don't see on the php website