CodeBodh
PHP

PHP 8.3 New Features You Should Know

Explore the most useful PHP 8.3 features, including typed class constants, the Override attribute, JSON validation, improved randomness, string functions, readonly improvements, and more.

Pardeep Patel By Pardeep Patel
Sep 29, 2026
5 min read
59 views
PHP 8.3 New Features You Should Know

PHP continues to evolve with each release, adding language improvements, better type safety, new developer tools, and useful standard-library functionality. PHP 8.3 introduced several features that can make modern applications cleaner, safer, and easier to maintain.

In this guide, we'll explore the most useful PHP 8.3 features developers should know, with practical examples and explanations of where they can be useful.

Note: PHP 8.3 was released on November 23, 2023. Before upgrading an existing application, review the official migration guide and test your application because PHP 8.3 also introduced backward-incompatible changes and deprecations.

1. Typed Class Constants

One of the most useful object-oriented improvements in PHP 8.3 is the ability to explicitly declare types for class constants.

Before PHP 8.3, you could define a constant like this:

class Config
{
public const VERSION = '1.0.0';
}

PHP 8.3 allows you to specify the expected type:

class Config
{
public const string VERSION = '1.0.0';
}

You can also use types such as:

class AppConfig
{
public const string NAME = 'CodeBodh';

public const int VERSION = 1;

public const bool DEBUG = false;

public const array FEATURES = [
'blog',
'products',
'authors'
];
}

This becomes particularly useful when working with interfaces and inheritance because implementations can no longer silently provide an incompatible constant value.

Why it matters

Typed constants make APIs more predictable and improve type safety in larger applications.

They can be especially useful for:

  1. Framework configuration
  2. Application constants
  3. API contracts
  4. Interfaces
  5. Domain models
  6. Shared configuration classes

2. The New #[\Override] Attribute

PHP 8.3 introduced the #[\Override] attribute.

It tells PHP that a method is intentionally overriding a method from a parent class or implemented interface.

For example:

class UserService
{
public function save(): void
{
// Save user
}
}

class AdminUserService extends UserService
{
#[\Override]
public function save(): void
{
// Save administrator
}
}

If the parent method does not exist, PHP will report an error.

This helps catch accidental method-name mistakes.

For example:

class AdminUserService extends UserService
{
#[\Override]
public function saev(): void
{
// Typo
}
}

The #[\Override] attribute makes this type of mistake much easier to detect.

Why it matters

This is particularly valuable in large object-oriented projects where classes may contain many inherited methods.

It can help with:

  1. Refactoring
  2. Large codebases
  3. Framework development
  4. Abstract classes
  5. Interfaces
  6. Testing
  7. Detecting accidental method-name changes

3. json_validate() Makes JSON Validation Easier

PHP 8.3 introduced the json_validate() function.

Previously, developers often used json_decode() simply to determine whether a JSON string was valid.

PHP 8.3 provides a dedicated function:

$json = '{"name":"CodeBodh","type":"marketplace"}';

if (json_validate($json)) {
echo "Valid JSON";
} else {
echo "Invalid JSON";
}

This is useful when you only need to validate the JSON and don't actually need to decode it.

For example:

$requestBody = file_get_contents('php://input');

if (!json_validate($requestBody)) {
http_response_code(400);

echo json_encode([
'error' => 'Invalid JSON'
]);

exit;
}

Important consideration

If you immediately need the decoded data, don't unnecessarily validate and then decode the same JSON.

For example, this performs two parsing operations:

if (json_validate($json)) {
$data = json_decode($json, true);
}

If your application needs the decoded value anyway, decode it directly and handle the result appropriately.

Where it is useful

json_validate() can be useful for:

  1. API request validation
  2. Webhooks
  3. Configuration files
  4. JSON imports
  5. AJAX requests
  6. External API integrations

4. Improved Readonly Property Cloning

Readonly properties were introduced in earlier PHP versions, but PHP 8.3 improves how readonly properties can be handled when cloning objects.

Consider an object containing another object:

class Profile
{
public function __construct(
public string $name
) {}
}

class User
{
public function __construct(
public readonly Profile $profile
) {}

public function __clone(): void
{
$this->profile = clone $this->profile;
}
}

This allows the cloned object to receive a cloned version of the readonly property during __clone().

Why deep cloning matters

Without deep cloning, two objects can potentially continue referencing the same nested object.

For applications dealing with:

  1. Immutable objects
  2. Configuration objects
  3. Domain models
  4. DTOs
  5. State snapshots

deep cloning can make object handling more predictable.

5. Dynamic Class Constant Fetching

PHP 8.3 makes dynamic access to class constants cleaner.

Suppose you have:

class Status
{
public const DRAFT = 'draft';
public const PUBLISHED = 'published';
}

You can store the constant name in a variable:

$name = 'PUBLISHED';

echo Status::{$name};

The result is:

published

This can be useful when the constant to retrieve is determined dynamically.

For example:

$status = 'DRAFT';

$value = Status::{$status};

echo $value;

Practical use cases

Dynamic class constants can be useful in:

  1. Configuration systems
  2. Status handlers
  3. Dynamic mappings
  4. Plugin systems
  5. Framework components
  6. Enum-like structures

6. New Randomizer Improvements

PHP 8.2 introduced the modern Random extension, and PHP 8.3 extends it with additional functionality.

One useful addition is:

Random\Randomizer::getBytesFromString()

Example:

use Random\Randomizer;

$randomizer = new Randomizer();

$code = $randomizer->getBytesFromString(
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
12
);

echo $code;

This can generate identifiers using only the characters you specify.

For example:

K8X2P7M4Q9AZ

You can use this type of functionality for application identifiers, short codes, or other randomly generated strings where a restricted character set is useful.

Random floating-point numbers

PHP 8.3 also adds:

$randomizer->getFloat();

and:

$randomizer->nextFloat();

For example:

use Random\Randomizer;

$randomizer = new Randomizer();

$value = $randomizer->nextFloat();

echo $value;

These additions provide better tools for applications that need controlled random floating-point values.

7. str_increment() and str_decrement()

PHP 8.3 introduces dedicated functions for incrementing and decrementing alphanumeric strings.

Instead of relying on string increment behavior:

$value = 'ABC';

$value++;

echo $value;

you can use:

$value = 'ABC';

echo str_increment($value);

Output:

ABD

The function also handles rollover:

echo str_increment('ZZ');

Output:

AAA

Similarly:

echo str_decrement('ABD');

can be used to move in the opposite direction.

Why this is useful

This can simplify applications that generate:

  1. Sequential codes
  2. Human-readable identifiers
  3. Version-like labels
  4. Alphanumeric references
  5. Test data

PHP 8.3 also changes and deprecates some older increment/decrement behaviors, so developers should prefer the dedicated functions for new code where appropriate.

8. mb_str_pad()

PHP 8.3 adds mb_str_pad() for padding multibyte strings.

This is particularly useful when working with international or Unicode text.

Example:

$text = 'CodeBodh';

echo mb_str_pad($text, 15, '-');

You can use it when formatting strings where multibyte characters need to be handled correctly.

This is useful for:

  1. Multilingual applications
  2. Reports
  3. CLI tools
  4. Text formatting
  5. Internationalized applications

9. Better CLI Linting

PHP's command-line syntax checker can now accept multiple files.

For example:

php -l file1.php file2.php file3.php

This is useful when checking a group of PHP files for syntax errors.

It can be particularly convenient in development workflows and scripts.

For example:

php -l src/*.php

You can incorporate this into development scripts or CI workflows to catch basic syntax problems before deployment.

10. More Improvements Across PHP

PHP 8.3 isn't only about a handful of headline features.

The release also introduces additional functionality across several extensions and components.

Examples include new DOM methods, additional Intl functionality, Reflection improvements, socket functionality, ZipArchive improvements, and new configuration capabilities.

Some of the new functions and methods include:

DatePeriod::createFromISO8601String()
DOMElement::getAttributeNames()
DOMElement::insertAdjacentElement()
DOMNode::contains()
DOMNode::getRootNode()
mb_str_pad()
ReflectionMethod::createFromMethodName()
str_increment()
str_decrement()
stream_context_set_options()
ZipArchive::getArchiveFlag()

This makes PHP 8.3 useful not only because of its language-level improvements but also because of the continued expansion of its standard library.

PHP 8.3 Deprecations You Should Know

Upgrading PHP isn't only about new features.

PHP 8.3 also introduced several deprecations and backward-incompatible changes that developers should review before upgrading production applications.

For example, certain uses of string increment/decrement behavior have been deprecated:

$value++;

when used with unsupported string values.

PHP 8.3 provides:

str_increment($value);

and:

str_decrement($value);

for explicit alphanumeric string operations.

Calling:

get_class();

and:

get_parent_class();

without arguments is also deprecated.

There are also changes involving functions such as range(), Date-related errors, SQLite3 error handling, and other areas of the language.

Before upgrading a production application, developers should review the PHP 8.3 migration guide and test their application thoroughly.

Should You Upgrade to PHP 8.3?

PHP 8.3 introduced meaningful improvements to the language, particularly around type safety, object-oriented programming, JSON validation, randomness, and developer tooling.

However, upgrading an existing application should be treated as a compatibility project rather than simply changing the PHP version.

Before upgrading:

  1. Create a complete backup.
  2. Check framework compatibility.
  3. Check third-party package compatibility.
  4. Review PHP 8.3 deprecations.
  5. Review backward-incompatible changes.
  6. Test the application in a staging environment.
  7. Run automated tests.
  8. Check application logs.
  9. Test database connectivity.
  10. Test cron jobs and background workers.
  11. Test APIs and webhooks.
  12. Only then upgrade production.

PHP 8.3 Compatibility Checklist

Before moving a project to PHP 8.3, check:

Application

  1. Does the application support PHP 8.3?
  2. Are there deprecated functions?
  3. Are there custom extensions?

Framework

Check the PHP requirements of your framework.

This is especially important for:

  1. Laravel
  2. Symfony
  3. WordPress
  4. CodeIgniter
  5. Drupal
  6. Custom PHP frameworks

Dependencies

Run your dependency manager and check package compatibility.

For Composer projects:

composer check-platform-reqs

You should also review your composer.json and lock file before deployment.

Testing

Run:

php -v

Then execute your application's test suite.

For example:

php artisan test

if you're working with Laravel.

PHP 8.3 vs Older PHP Versions

The most important reason to learn PHP 8.3 isn't that every project needs to immediately use every new feature.

Instead, developers should understand which improvements solve real problems.

For example:

FeatureUseful For
Typed class constantsStronger type safety
#[\Override]Safer inheritance and refactoring
json_validate()Efficient JSON validation
Readonly cloning improvementsImmutable object designs
Dynamic class constantsDynamic configuration
Randomizer::getBytesFromString()Controlled random identifiers
Randomizer::getFloat()Random floating-point values
str_increment()Alphanumeric sequences
str_decrement()Reverse alphanumeric sequences
mb_str_pad()Multibyte string formatting
Multi-file php -lDevelopment and CI workflows

Final Thoughts

PHP 8.3 is a practical evolution of the language rather than a complete redesign. Its most noticeable improvements include typed class constants, the #[\Override] attribute, json_validate(), improved readonly cloning, enhanced randomness APIs, dynamic class constant access, and new string functions.

For developers maintaining modern PHP applications, these features can make code more explicit, maintainable, and easier to validate.

If you're starting a new PHP project, understanding PHP 8.3 also gives you a better foundation for writing modern PHP rather than relying on older language patterns.

Before upgrading an existing application, however, always check framework and dependency compatibility and test the application against PHP 8.3 in a staging environment first.


Official references used for the technical details: PHP 8.3 Release Announcement · PHP 8.3 Migration Guide · PHP 8.3 New Functions

Pardeep Patel

Creator and developer contributing high quality tutorials, guides and resources on CodeBodh.

Comments (0)

Security check against automated spam
6 × 5 = ?