PHP 8.4 is the next scheduled release of the popular programming language, offering new features, performance improvements, and better memory management. It was released at the end of 2024 and has introduced many changes that will make it easier for developers to create more secure and efficient applications.

✅ New Features in PHP 8.4

🔹 Readonly Classes

Following the successful introduction of readonly properties in PHP 8.1, PHP 8.4 takes it a step further by allowing an entire class to be declared as readonly. This means that all properties of the class will automatically be immutable.


readonly class Xristis {
    public function __construct(
        public string $onoma,
        public string $email
    ) {}
}

Any attempt to change a property of this class will result in an error, thereby ensuring greater data integrity.

🔹 Typed Class Constants

PHP 8.4 introduces type support for class constants. This improves code security and facilitates error detection.


class Rythmiseis {
    public const string API_URL = "https://api.example.com";
    public const int XPONOS = 30;
}

🔹 New Function json_validate()

The new function json_validate() allows you to validate a JSON string without having to use json_decode(), making the process more efficient.


$json = '{"onoma": "Giannis", "ilikia": 30}';
if (json_validate($json)) {
    echo "Valid JSON!";
}

🔹 Improvements to array_map() and array_filter()

The functions array_map() and array_filter() have become more strict regarding the data type of their returned values, thereby improving code security.

🚀 Performance Improvements

🔹 Faster foreach Loops

foreach loops with references are now more efficient, reducing memory consumption.

🔹 Opcache Optimization

The JIT compiler and Opcache have been further optimized, speeding up code execution.

🔹 Better Memory Management in Arrays

Arrays now consume less memory, making them more efficient.

❌ Deprecations and Changes

🔹 Removal of create_function()

create_function() has been completely removed from PHP 8.4. It is recommended to use anonymous functions (closures).

🔹 str_split() Now Supports Multi-Byte Characters

The str_split() function now supports multi-byte characters (e.g., Greek), fixing issues present in previous versions.

🎯 Conclusion

PHP 8.4 brings numerous improvements, offering greater security, speed, and reliability. If you are a PHP developer, it is good practice to try PHP 8.4 and adapt your code to the new features.