PHP 8.4 will be released on November 21, 2024. It'll include property hooks, HTML 5 support, as well as chaining methods on new without additional par

What's new in PHP 8.4

submited by
Style Pass
2024-11-21 11:00:06

PHP 8.4 will be released on November 21, 2024. It'll include property hooks, HTML 5 support, as well as chaining methods on new without additional parentheses — a big one!

One of the biggest changes in modern-PHP history: the ability to define property hooks, eliminating the need for a lot of boilerplate code.

The goal of property hooks is to remove a lot of getters and setters, by allowing each property to define its own get and set hooks. Hooks are optional, and you don't have to add both of them on a specific property. For example, a property with only a get hook is virtual property.

There is a lot to say about property hooks, and I plan to write a followup post on them soon, so make sure to subscribe if you want to know when that one is done. One final thing I'd like to mention — probably what I'm most hyped about: property hooks can be defined in interfaces!

As if property hooks alone wasn't enough, PHP 8.4 has another feature that will save so much boilerplate code: you don't have to wrap new invocations within parenthesis anymore to be able to chain methods on them. So instead of doing this:

Leave a Comment