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:
PHP 8.3 allows you to specify the expected type:
You can also use types such as:
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:
- Framework configuration
- Application constants
- API contracts
- Interfaces
- Domain models
- 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:
If the parent method does not exist, PHP will report an error.
This helps catch accidental method-name mistakes.
For example:
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:
- Refactoring
- Large codebases
- Framework development
- Abstract classes
- Interfaces
- Testing
- 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:
This is useful when you only need to validate the JSON and don't actually need to decode it.
For example:
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 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:
- API request validation
- Webhooks
- Configuration files
- JSON imports
- AJAX requests
- 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:
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:
- Immutable objects
- Configuration objects
- Domain models
- DTOs
- 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:
You can store the constant name in a variable:
The result is:
This can be useful when the constant to retrieve is determined dynamically.
For example:
Practical use cases
Dynamic class constants can be useful in:
- Configuration systems
- Status handlers
- Dynamic mappings
- Plugin systems
- Framework components
- 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:
Example:
This can generate identifiers using only the characters you specify.
For example:
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:
and:
For example:
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:
you can use:
Output:
The function also handles rollover:
Output:
Similarly:
can be used to move in the opposite direction.
Why this is useful
This can simplify applications that generate:
- Sequential codes
- Human-readable identifiers
- Version-like labels
- Alphanumeric references
- 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:
You can use it when formatting strings where multibyte characters need to be handled correctly.
This is useful for:
- Multilingual applications
- Reports
- CLI tools
- Text formatting
- Internationalized applications
9. Better CLI Linting
PHP's command-line syntax checker can now accept multiple files.
For example:
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:
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:
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:
when used with unsupported string values.
PHP 8.3 provides:
and:
for explicit alphanumeric string operations.
Calling:
and:
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:
- Create a complete backup.
- Check framework compatibility.
- Check third-party package compatibility.
- Review PHP 8.3 deprecations.
- Review backward-incompatible changes.
- Test the application in a staging environment.
- Run automated tests.
- Check application logs.
- Test database connectivity.
- Test cron jobs and background workers.
- Test APIs and webhooks.
- Only then upgrade production.
PHP 8.3 Compatibility Checklist
Before moving a project to PHP 8.3, check:
Application
- Does the application support PHP 8.3?
- Are there deprecated functions?
- Are there custom extensions?
Framework
Check the PHP requirements of your framework.
This is especially important for:
- Laravel
- Symfony
- WordPress
- CodeIgniter
- Drupal
- Custom PHP frameworks
Dependencies
Run your dependency manager and check package compatibility.
For Composer projects:
You should also review your composer.json and lock file before deployment.
Testing
Run:
Then execute your application's test suite.
For example:
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 constants | Stronger type safety |
#[\Override] | Safer inheritance and refactoring |
json_validate() | Efficient JSON validation |
| Readonly cloning improvements | Immutable object designs |
| Dynamic class constants | Dynamic 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 -l | Development 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
Comments (0)