PHP 8.3 continues the language’s modernization with several exciting new features and improvements. Here’s what you need to know:
1. Typed Class Constants
PHP 8.3 allows type declarations for class constants:
class MyClass {
const string NAME = 'MyClass';
const int VERSION = 1;
}
2. json_validate() Function
A new function specifically for validating JSON strings without decoding them:
if (json_validate($jsonString)) {
// Valid JSON
}
3. Dynamic Class Constant Fetch
You can now fetch class constants dynamically:
$constantName = 'VERSION';
echo MyClass::{$constantName};
4. Improved Randomness
The Random extension gets new methods for generating random floats and shuffled arrays.
5. #[\Override] Attribute
Explicitly mark methods that override parent methods:
class Child extends Parent {
#[\Override]
public function method() {}
}
Performance Improvements
PHP 8.3 includes various performance optimizations, particularly for JIT compilation and garbage collection.
Upgrading to PHP 8.3 gives you access to these modern features while maintaining backward compatibility with most existing code.
