The overlooked new php 8.4 features
david duymelinck
Posted on November 28, 2024
Most of the posts about php 8.4 are about property hooks, asymmetric property visibility, the new array functions and the new html features.
But there are a few more features that deserve attention.
The deprecated attribute
Before php 8.4 the only way to document deprecated code was to add a @deprecated
comment tag. Now this is an attribute with message and since properties.
A use case could be adding it to an older version of the api.
[#\Deprecated(message: 'Use route /v2/something', since: 'v2')]
PDO specific driver subclasses
Before php 8.4 the drivers were a subsclasses of the PDO class. This meant that the subclass could have extra methods or not. Now you need to call the driver class that fits your database.
The main benefit is that the database is not only known by looking at the connection string.
Lazy objects
Most developers know lazy loading from ORM entities. But now php made it a language feature. If you don't have expensive classes on creation, you probably don't need this feature.
This will improve the code for packages that use a lazy strategy.
New mb_* functions
If you are working with multibyte strings mb_trim()
, mb_ltrim()
, mb_rtrim()
, mb_ucfirst()
, and mb_lcfirst()
can be a welcome addition.
Posted on November 28, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 28, 2024