Laravel & Ecosystem (50 Qs)•Part 1: Architecture, Service Container & Request Lifecycle (1 - 10)
What are the key features introduced in modern PHP (PHP 8.0 to 8.3)?
senior LevelCode ExampleLifecycleDocker & ContainersSystem Design
In Simple Words: Modern PHP has undergone a massive evolution into a strictly typed, high-performance language:
- JIT Compiler (PHP 8.0): Compiles opcode into machine code for CPU-intensive tasks.
- Named Arguments & Match Expressions:
match($val)replaces clunkyswitchstatements with strict type comparison and return expressions. - Attributes: Native metadata annotations (
#[Route('/api')]) replacing DocBlock comments. - Constructor Property Promotion: Declares and assigns class properties directly in the constructor signature.
- Enums & Readonly Classes (PHP 8.1/8.2): First-class typed enums and immutable classes.
- Typed Class Constants & Dynamic Class Constant Fetch (PHP 8.3).
php
// Modern PHP 8.2 / 8.3 Syntax:
enum OrderStatus: string {
case Pending = 'pending';
case Shipped = 'shipped';
case Cancelled = 'cancelled';
}
readonly class UserDTO {
public function __construct(
public int $id,
public string $email,
public OrderStatus $status
) {}
}