Top New Features in PHP 8.3 You Need to Know About!
PHP 8.3 brings a range of exciting new features and improvements to the PHP language, enhancing functionality and developer experience…
Top New Features in PHP 8.3 You Need to Know About!

php8.3 new features
PHP 8.3 brings a range of exciting new features and improvements to the PHP language, enhancing functionality and developer experience. This article provides a comprehensive overview of these updates, including typed class constants, dynamic class constant fetching, new attributes, deep-cloning of readonly properties, and more. Our objective is to help you understand these new features and learn how to integrate them into your projects effectively.
1. Typed Class Constants
What Are They?
In PHP 8.3, class constants can now be type-declared. This means that you can specify the type of a class constant, which adds an additional layer of type safety to your code.
Syntax:
const TYPE TYPE_CONSTANT = VALUE;
Benefits: Type safety is a major benefit, as it helps prevent type-related bugs by enforcing the expected data types.
Example:
<?php
class MyClass {
public const int MAX_SIZE= 100;
}
echo MyClass::MAX_SIZE; // Output: 100
2. Dynamic Class Constant Fetch
What Is It?
This feature allows for the dynamic fetching of class constants using variable names. It introduces flexibility by letting you access constants based on variable content.
Benefits: Increased flexibility in accessing constants dynamically.
Example:
<?php
class Foo {
const PHP = 'PHP 8.3';
}
$searchableConstant = 'PHP';
var_dump(Foo::{$searchableConstant});
3. New #[\Override] Attribute
What Is It?
PHP 8.3 introduces the #[\Override] attribute to indicate that a method in a subclass overrides a method in its parent class. This feature aids in clearer documentation and automatic checking of method overrides.
Benefits: Improved code documentation and automatic verification of method overrides.
Example:
<?php
class ParentClass {
public function method() {}
}
class ChildClass extends ParentClass {
#[\Override]
public function method() {}
}
4. Deep-Cloning of Readonly Properties
What Is It?
This feature supports the deep-cloning of objects that contain readonly properties. It ensures that readonly properties are cloned correctly without modification.
Benefits: Ensures that readonly properties remain intact when cloning objects.
Example:
class PHP {
public string $version = '8.2';
}
readonly class Foo {
public function __construct(
public PHP $php
) {}
public function __clone(): void {
$this->php = clone $this->php;
}
}
$instance = new Foo(new PHP());
$cloned = clone $instance;
$cloned->php->version = '8.3';
5. New json_validate() Function
What Is It?
The json_validate() function is a new addition that validates JSON strings to ensure they adhere to proper syntax.
Benefits: Simplifies the process of validating JSON data.
Example:
<?php
var_dump(json_validate('{ "test": { "foo": "bar" } }')); // true
6. New Randomizer::getBytesFromString() Method
What Is It?
This method generates random bytes based on a given string seed, which is particularly useful for cryptographic and random data generation.
Benefits: Provides a mechanism for generating random bytes with a specified seed.
Example:
<?php
// A \Random\Engine may be passed for seeding,
// the default is the secure engine.
$randomizer = new \Random\Randomizer();
$randomDomain = sprintf(
"%s.example.com",
$randomizer->getBytesFromString(
'abcdefghijklmnopqrstuvwxyz0123456789',
16,
),
);
echo $randomDomain;
7. New Randomizer::getFloat() and Randomizer::nextFloat() Methods
What Are They?
The Randomizer::getFloat() and Randomizer::nextFloat() methods generate random float values within a specified range, offering greater precision and control over random number generation.
Benefits: Enhanced control over random float values.
Example:
<?php
$randomizer = new \Random\Randomizer();
$temperature = $randomizer->getFloat(
-89.2,
56.7,
\Random\IntervalBoundary::ClosedClosed,
);
$chanceForTrue = 0.1;
// Randomizer::nextFloat() is equivalent to
// Randomizer::getFloat(0, 1, \Random\IntervalBoundary::ClosedOpen).
// The upper bound, i.e. 1, will not be returned.
$myBoolean = $randomizer->nextFloat() < $chanceForTrue;
8. Command Line Linter Supports Multiple Files
What Is It?
PHP 8.3 allows linting multiple PHP files in a single command, streamlining the process of code validation.
Benefits: Increases efficiency by enabling the validation of several files simultaneously.
Example:
php -l foo.php bar.php
No syntax errors detected in foo.php
No syntax errors detected in bar.php
9. Negative Index Handling in Arrays
What Is It?
When assigning a negative index to an empty array, PHP 8.3 changes the behavior so that the next index will be n + 1 instead of 0.
Benefits: Provides a more intuitive approach to managing array indices.
Example:
<?php
$array = [];
$array[-6] = 'value';
$array[-7] = 'value2';
$array[]= 'value3';
print_r($array); // Output: Array ( [-6] => 'value' [-7] => 'value2' [-5] => 'value3')
Conclusion
PHP 8.3 introduces a host of new features and improvements that enhance the language’s functionality and developer productivity. From typed class constants to dynamic class constant fetching, new attributes, and better array handling, these updates aim to refine coding practices and streamline workflows. For a deeper understanding, developers are encouraged to explore the official PHP documentation and other relevant resources.
You can also watch a comprehensive overview of PHP 8.3 in action on this YouTube video.
메타데이터
- post_id
- 7b2db3a6e379
- slug
- top-new-features-in-php-8-3-you-need-to-know-about-7b2db3a6e379
- url
- https://medium.com/@naseem.ali30/top-new-features-in-php-8-3-you-need-to-know-about-7b2db3a6e379
- canonical_url
- https://medium.com/@naseem.ali30/top-new-features-in-php-8-3-you-need-to-know-about-7b2db3a6e379
- author_url
- https://medium.com/@naseem.ali30
- status
- ok
- fetched_at
- 2026-06-27 23:56:40