PHP 8.3 was released in November 2023 and remains widely deployed in 2026 as the stable PHP version on most hosting platforms. It introduced several meaningful language improvements that make PHP code safer, more expressive, and easier to maintain. This guide covers everything PHP 8.3 added and how to apply each feature in real code.
Table of Contents
1. Typed Class Constants
Before PHP 8.3, class constants had no type declarations — they could hold any value and there was no way to enforce that they matched an expected type.
// PHP 8.2 and earlier — no type enforcement:
class Status {
const ACTIVE = 'active';
const INACTIVE = 'inactive';
const TIMEOUT = 30; // Could be anything
}
// PHP 8.3 — typed constants:
class Status {
const string ACTIVE = 'active';
const string INACTIVE = 'inactive';
const int TIMEOUT = 30;
const bool ENABLED = true;
const array VALID = ['active', 'inactive'];
}
Typed constants are particularly valuable in interfaces, where they enforce that implementing classes provide the correct type:
interface PaymentGateway {
const string CURRENCY = 'PHP'; // Must be a string
const int MAX_AMOUNT = 100000; // Must be an int
public function charge(float $amount): bool;
}
2. The #[Override] Attribute
The #[Override] attribute signals to PHP (and static analysis tools like PHPStan) that a method intentionally overrides a parent class method. If the parent method doesn’t exist or gets renamed, PHP throws an error — catching bugs that previously went unnoticed until runtime.
class ParentClass {
public function process(): string {
return 'parent processing';
}
}
class ChildClass extends ParentClass {
#[Override]
public function process(): string { // PHP verifies this overrides a real parent method
return 'child processing';
}
#[Override]
public function nonExistent(): string { // PHP ERROR: nonExistent() not in parent
return 'this breaks';
}
}
This is especially useful in large codebases where refactoring a parent class might silently break child class method overrides that were expected to be called polymorphically.
3. json_validate()
PHP 8.3 introduced json_validate() — a function that checks whether a string is valid JSON without actually decoding it. Before this, you had to call json_decode() and check json_last_error(), which was wasteful when you only needed to validate:
// PHP 8.2 and earlier — decode just to validate:
$data = '{"name": "Lyndon", "age": 25}';
json_decode($data);
$isValid = json_last_error() === JSON_ERROR_NONE; // Decodes the whole thing
// PHP 8.3 — validate without decoding:
$isValid = json_validate($data); // True — no full decode, much faster for validation
$invalid = '{"name": "broken}';
var_dump(json_validate($invalid)); // bool(false)
// Useful for validating incoming API payloads before processing:
function handleWebhook(string $payload): void {
if (!json_validate($payload)) {
throw new InvalidArgumentException('Invalid JSON payload');
}
$data = json_decode($payload, true);
// process $data...
}
4. Readonly Classes
PHP 8.1 introduced readonly properties. PHP 8.2 extended this to allow all properties of a class to be marked readonly at once with the readonly class modifier. PHP 8.3 refined the behaviour and improved compatibility.
readonly class UserDTO {
public function __construct(
public string $name,
public string $email,
public int $age,
) {}
// All properties are automatically readonly — no individual annotations needed
}
$user = new UserDTO('Lyndon', 'lyndon@example.com', 25);
echo $user->name; // Lyndon
$user->name = 'Maria'; // Error: Cannot modify readonly property
Readonly classes are ideal for Data Transfer Objects (DTOs), Value Objects, and any data structure that should be immutable after construction. They are particularly useful in Laravel for request payload handling and response transformation.
5. Improved Unserialize() Error Handling
PHP 8.3 emits a deprecation warning when unserialize() is called with an untrusted string and the allowed_classes option is not explicitly set. This encourages developers to explicitly whitelist deserializable classes, improving security against PHP object injection attacks:
// PHP 8.3 — explicit allowed_classes (secure):
$data = unserialize($stored_value, ['allowed_classes' => false]); // Only scalars/arrays
$data = unserialize($stored_value, ['allowed_classes' => [User::class]]); // Only User objects
// PHP 8.3 — deprecated (produces deprecation notice):
$data = unserialize($stored_value); // Implicit allowed_classes not specified
6. Dynamic Class Constant and Enum Fetch
PHP 8.3 allows using variable expressions to fetch class constants and enum cases, which was not possible before:
// PHP 8.2 — not allowed:
$const = 'ACTIVE';
echo Status::$const; // Error
// PHP 8.3 — dynamic constant fetch works:
$const = 'ACTIVE';
echo Status::{$const}; // 'active'
// Dynamic enum case fetch:
enum Color { case Red; case Green; case Blue; }
$case = 'Red';
$color = Color::{$case}; // Color::Red enum case
echo $color->name; // Red
7. Randomizer Additions
PHP 8.2 introduced the Random\Randomizer class. PHP 8.3 added new methods to it:
use Random\Randomizer;
$r = new Randomizer();
// getBytesFromString() — random bytes chosen from a specific character set:
$token = $r->getBytesFromString('ABCDEFabcdef0123456789', 32);
echo $token; // e.g. "f3A2c9B1d7E4a6F8..."
// getFloat() — precise float in [0, 1):
$float = $r->getFloat(0.0, 1.0);
// nextFloat() — random float between 0 and 1:
$float = $r->nextFloat();
8. Performance Improvements
PHP 8.3 includes multiple internal performance improvements:
- Reduced memory allocations in common operations (array operations, string handling)
- Improved JIT compilation — PHP’s Just-In-Time compiler is more effective in PHP 8.3 for CPU-intensive workloads
- Faster Fibers — async PHP via fibers has reduced overhead
- Class autoloading cache improvements — frequently-used classes are cached more efficiently
Benchmarks show PHP 8.3 is approximately 5–10% faster than PHP 8.2 on typical web application workloads. Combined with OPcache, a well-optimized PHP 8.3 application is significantly faster than the equivalent PHP 7.x code.
Migrating to PHP 8.3
For most PHP applications, upgrading from 8.1 or 8.2 to 8.3 is straightforward. The key checks before upgrading:
- Run
composer update— check that your dependencies support PHP 8.3 - Check for deprecated function usage with PHPStan or PHP_CodeSniffer
- Test on a staging environment before upgrading production
- Review any
unserialize()calls and add explicitallowed_classes
On Hostinger, SiteGround, and A2 Hosting, switching PHP version is a one-click operation in the control panel. On shared hosting, the upgrade is reversible if issues arise.
Frequently Asked Questions
Is PHP 8.3 stable enough for production?
Yes. PHP 8.3 is the active release version in 2026 with full security and bug fix support. PHP 8.1 received its final security fix in late 2025. If you are on 8.1 or 8.2, upgrading to 8.3 is strongly recommended for the security updates alone.
Does Laravel 11 support PHP 8.3?
Yes. Laravel 11 requires PHP 8.2+ and fully supports PHP 8.3. The Laravel ecosystem (Livewire, Inertia, Nova) also supports PHP 8.3.
What happened to PHP 9?
PHP 9.0 is on the long-term roadmap but not released as of 2026. PHP 8.x is the current major version line. Future releases (8.4, 8.5) will continue adding features without the breaking changes that a major version bump would introduce.
Conclusion
PHP 8.3 is a solid incremental improvement over 8.2: typed class constants prevent silent type errors in constants, #[Override] catches accidental method signature mismatches, and json_validate() simplifies a common validation pattern. For production PHP applications running PHP 8.0 or 8.1, upgrading to 8.3 is worth doing both for the new features and the continued security support.
Next Step for Your Project Journey
Pick your next action to keep building: download complete source code, continue with practical tutorials, or explore more project systems.

