Back to homepage
#php

What's New in PHP 8.3?

3 min read

PHP 8.3 focuses primarily on refinement and housekeeping rather than major overhauls. The release introduces several notable features including the new `json_validate` function for efficient JSON validation, typed constants for improved code clarity, and enhancements to the Randomizer class with new methods for handling random values. The update also adds the `#[\Override]` attribute for safer method inheritance and includes various deprecations to streamline the language.

What's New in PHP 8.3?

PHP 8.3 has officially landed today, marking a significant step in the language's ongoing evolution.

As we delve into this latest update, we uncover a mix of refinements, new features, and important deprecations that collectively aim to streamline PHP's capabilities and align them more closely with modern programming paradigms.

Spring Cleaning in PHP 8.3: A Focus on Refinement

Unlike the substantial overhauls seen in PHP 8.1 and 8.2, PHP 8.3 leans towards ‘housekeeping', ensuring the language stays clean, efficient, and coherent with its recent trajectory.

Introducing json_validate: A Leap in JSON Handling

A notable addition is the json_validate function.

Preceded by json_decode, this new function offers a more resource-efficient way to validate JSON strings, enhancing performance and simplifying implementations.

json_validate

Typed Constants and Dynamic Access: A Stride Towards Clarity

PHP 8.3 brings a game-changing feature: the ability to type constants.

typed constants

This enhancement, along with the newfound capability to access constants dynamically, will undoubtedly elevate the clarity and robustness of PHP code.

randomizer class enhancements

Randomizer Class Enhancements: Refined Randomness

Building on the Randomizer class introduced in PHP 8.2, PHP 8.3 adds three new methods:

  • getBytesFromString(): Randomly selects a specified number of characters from a string.

getBytesFromString

  • getFloat(): Generates a random float within a given range.
  • nextFloat(): Similar to getFloat, but always returns a float between 0 and 1, without requiring parameters.

getFloat

The #[\Override] Attribute: Safeguarding Method Overrides

The #[\Override] attribute is a new safety net, ensuring that a method indeed overrides a parent class method.

PHP will now throw an error if the method does not exist in the parent class, reducing the risk of unintended behaviors in code evolution.

For example:

override attribute

More Improvements and Deprecated Elements

Other notable changes in PHP 8.3 include:

  • Resetting readonly properties during object cloning.
  • More detailed error messages for Date and Time class exceptions.
  • Enhanced error handling for unserialize().
  • Deprecation of INI parameters assert.active, assert.bail, assert.callback, assert.exception, and assert.warning.
  • Deprecated use of get_class() and get_parent_class() without arguments.

For a deeper dive into PHP 8.3, its official release page offers extensive insights and details.