Home >Backend Development >PHP Tutorial >The overlooked new php features

The overlooked new php features

DDD
DDDOriginal
2024-11-30 12:22:12507browse

The overlooked new php  features

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 @deprecatedcomment 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.

The above is the detailed content of The overlooked new php features. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn