PHP has come a long way from its humble beginnings. With PHP 8.4, we're seeing features that make code not just functional, but actually enjoyable to write. Let's dive into the highlights.
Strict Types: Your New Best Friend
declare(strict_types=1);
function calculateTotal(int $quantity, float $price): float {
return $quantity * $price;
}
Strict typing catches bugs before they reach production. It's like having a vigilant code reviewer who never sleeps.
Match Expressions: Switch's Cooler Sibling
Gone are the days of verbose switch statements:
$message = match($statusCode) {
200 => 'Success!',
404 => 'Not found',
500 => 'Server error',
default => 'Unknown status',
};
Clean, expressive, and returns values directly. What's not to love?
Arrow Functions: Less Typing, More Doing
When you need a simple callback, arrow functions are perfect:
$doubled = array_map(fn($x) => $x * 2, [1, 2, 3, 4]);
One line. No ceremony. Just pure functionality.
Readonly Properties: Immutability Made Easy
class Config {
public function __construct(
private readonly string $envPath
) {}
}
Once set, these properties can't be changed. Perfect for configuration objects and value objects.
The Bottom Line
PHP 8.4 isn't just an update—it's a statement. It says that PHP is a modern, powerful language that respects developers' time and sanity.
If you're still on PHP 7.x, now's the time to upgrade. Your future self will thank you. Put these features to work in building REST APIs with PHP, or see how they compare to Spring Boot with Kotlin for type-safe backends. For practical applications, check out how this website uses modern PHP for static + smart hybrid architecture. And remember: even modern PHP benefits from API-first design principles.