PHP 8.0 introduced the JIT compiler for better performance, named arguments, union types, the match expression, the null safe operator, and constructor property promotion. It made type error handling much more consistent.
PHP 8 Highlights
// 1. Named arguments
htmlspecialchars(string: $s, double_encode: false);
// 2. Union types
function process(int|string $input): int|false {}
// 3. Match expression
$val = match($x) { 1 => "one", 2 => "two", default => "other" };
// 4. Null safe operator
$city = $user?->address?->city;
// 5. Constructor promotion
class Point { public function __construct(
public float $x, public float $y
) {} }
// 6. str_contains / str_starts_with / str_ends_with
str_contains("Hello World", "World"); // true
str_starts_with("Hello", "He"); // true
str_ends_with("Hello", "lo"); // true
// 7. Attributes (annotations)
#[Route("/users", methods: ["GET"])]
class UserController {}
// 8. throw as expression
$name = $input ?? throw new InvalidArgumentException("Required");
// 9. JIT compiler (Just-In-Time) — faster numeric code