Key New Features in PHP 8.4
PHP 8.4 brings a collection of developer‑friendly enhancements—including readonly independent properties, string‑key array unpacking, JIT performance gains, typed class constants, improved error messages, an upgraded type system, and stronger Fiber support—aimed at making code cleaner, faster and more maintainable.
PHP 8.4, the latest release of the popular server‑side language, introduces exciting new features, performance improvements and developer‑friendly enhancements designed to help developers write cleaner, more efficient and maintainable code.
1. Readonly Independent Properties
PHP 8.4 extends the readonly attribute so it can be applied to independent properties, not only class properties, increasing flexibility and ensuring immutability of specific attributes, which improves encapsulation and supports better design‑pattern usage.
class Product {
public readonly int $id;
public function __construct(int $id) {
$this->id = $id;
}
}
$product = new Product(101);
echo $product->id; // 1012. Array Unpacking with String Keys
The new version allows associative arrays to be unpacked using string keys, simplifying array merging without extra key‑management code.
$array1 = ['name' => 'John'];
$array2 = ['age' => 30];
$result = [...$array1, ...$array2];
print_r($result);
// Output:
// ['name' => 'John', 'age' => 30]3. Performance Enhancements
PHP 8.4 continues performance optimisation, especially for the Just‑In‑Time (JIT) compiler, delivering noticeable speed gains for compute‑intensive applications and large‑scale systems.
4. Extended Attributes Usage
Building on the attribute system introduced in PHP 8.0, PHP 8.4 enables more complex and powerful attribute‑driven functionality such as routing and validation logic.
#[Route('/home')]
class HomeController {
#[Method('GET')]
public function index() {
return "Welcome to Home!";
}
}5. Typed Class Constants
Class constants can now declare their type, enhancing type safety and readability.
class Config {
public const string DB_HOST = 'localhost';
public const int MAX_CONNECTIONS = 100;
}
echo Config::DB_HOST; // localhost
echo Config::MAX_CONNECTIONS; // 1006. Improved Error Messages
Error output has been refined to provide more detailed, actionable information, making debugging easier and faster.
7. Enhanced Type System
Further tightening of type checks and better alignment with modern coding standards make code clearer and more reliable.
8. Asynchronous Programming with Fibers
PHP 8.4 adds several improvements to the Fiber API introduced in PHP 8.1, allowing developers to implement asynchronous workflows without sacrificing performance or adding complexity.
$fiber = new Fiber(function() {
echo "Fiber is running...\n";
});
$fiber->start();9. Deprecation Notices
Obsolete features are deprecated with guidance for modern alternatives, paving the way for a cleaner and more modern syntax in future releases.
Overall, PHP 8.4 represents a significant step forward, offering stronger performance, a more concise syntax, and a robust type system that empower developers to build modern applications with confidence.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.