New PHP Standard: What Awaits Developers in 2024
The PHP community continues to delight developers: at the end of 2023, the final release of PHP 8.3 was released, and PHP 8.4 is expected in 2024. These versions set a new quality standard for one of the most popular web programming languages. Let's look at the key changes awaiting developers and how to prepare for the transition.
Key Innovations in PHP 8.3
Version 8.3 has received stable release status and includes a number of improvements that make code cleaner, safer, and faster:
- Typed class constants — you can now explicitly specify the type of a constant:
final public const string MY_CONST = 'value';. This improves readability and helps static analyzers. - #[Override] attribute — explicitly indicates that a method overrides the parent method. If the method in the parent changes or disappears, PHP will throw an error. Great protection against regressions.
- Deep cloning of readonly properties — you can now modify readonly properties when cloning an object, simplifying work with immutable DTOs.
- Improved json_validate() function — a fast way to check if a string is valid JSON without fully parsing it. Saves memory and time.
- New array methods —
array_any()andarray_all()allow you to concisely check whether at least one (or all) elements satisfy a condition.
What PHP 8.4 Has in Store?
Although the PHP 8.4 release is expected by the end of 2024, several significant RFCs (Requests for Comments) are already being discussed:
- Property Hooks — a long-awaited feature to add getters and setters directly to class properties without writing separate methods. This will make code more declarative and reduce boilerplate code.
- Asymmetric visibility — the ability to set different access levels for reading and writing a property. For example, public reading but protected writing.
- Improved JIT performance — work on the Just-In-Time compiler continues. A 10–20% performance increase for heavy computations is expected.
- Intersection Types support — will allow declaring parameters that must implement multiple interfaces simultaneously, for example:
function foo(Countable&Stringable $obj).
How to Prepare for the Update?
Upgrading to a new PHP version means not only new features but also potential breaking changes. We recommend the following action plan:
- Check code compatibility — use static analyzers (PHPStan, Psalm) with the maximum strictness level. They will highlight deprecated constructs.
- Update dependencies — make sure all libraries and frameworks you use (Laravel, Symfony, WordPress) support PHP 8.3+.
- Test on staging — deploy the new version in a test environment, run automated tests, and check key scenarios.
- Use modern PHP — gradually adopt attributes, type hints, readonly classes, and other features. This will ease future updates.