search
HomeBackend DevelopmentPHP8A new version of PHP 8.3 is about to be released: an overview of new features

PHP 8.3 will be updated on November 23, 2023. It will add typed class constants, a new helper function for json_validate to check json payloads, and some minor improvements to the Randomizer class, reading ini configuration, etc.

A new version of PHP 8.3 is about to be released: an overview of new features

#The PHP team will release a new minor version of PHP at the end of this month. The new version will mainly contain improvements and features that, except for a few, will not be very relevant for end users.

Typed Class Constants

We all use constants at some point. So far, the type of a constant has been inferred from its value. This also means that the ability to inherit or implement a class can change the type. In a nutshell, the new functionality will look like this:

class Foo {
   public int BAZ = 1;
}

Validate JSON payload

In almost all situations where JSON must be read, transformed, and written , must be verified first. You can do a "test decode" to see if an exception is thrown, or just set up an else branch for invalid payload cases.

For smaller payloads this might be ok, but decoding a very large JSON string into an array just to check if it's valid is not elegant. Additionally, it can cause memory and/or performance issues.

The new json_validate function promises to check whether a given string is valid JSON and is more performant and memory efficient. As shown below:

json_validate(string $json, int $depth = 512, int $flags = 0): bool

Further improvements

As I said, there are further improvements in the upcoming PHP 8.3 version. Since I personally don't think they are important, I just want to mention them here for completeness.

  1. Randomizer Improvements: Small improvements, such as specifying a range for random floating point values ​​or defining the string length.

  2. Read-only revision: Allow read-only properties to be reinitialized on cloning. This seems like an edge case, but may be important for deep cloning.

  3. #[Override] attribute: This attribute is used to express the programmer's "intention". It essentially says "I know this method comes from the parent class and I want to override it. If this changes, please let me know."

  4. Anonymous read-only class: somewhat self-explanatory. Until now, there was no way to create them, now PHP introduces it.

  5. Dynamic class constant acquisition: PHP allows the use of curly braces to read dynamic class properties. With 8.3, it's also possible to read constants (seriously, don't do that).

  6. Static properties in Traits: Static properties inherited from the parent class will be redeclared. Personally, it's an evil mix of everything you can do in PHP. Why? check.

there are more. Since I personally don't think they are relevant, I haven't listed them here. For a complete list of all changes, check out the official migration guide.

Conclusion

As with every new release, there is no golden rule to follow whether to update or not. We strongly recommend using the latest version, as it often fixes bugs and bugs in previous versions and provides better performance and functionality.

The above is the detailed content of A new version of PHP 8.3 is about to be released: an overview of new 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools