What is event-driven programming in PHP?
Answer
Event-driven programming decouples the code that detects something happening (event dispatcher) from the code that handles it (event listeners). In PHP, PSR-14 defines the standard EventDispatcherInterface. In Laravel: fire an event with event(new UserRegistered($user)) and listen with class SendWelcomeEmail { public function handle(UserRegistered $event) { ... } }. Symfony's EventDispatcher is the reference implementation. Benefits: open for extension (add listeners without touching the dispatching code), decoupled code (listener does not know about the dispatcher's context), and multiple listeners can react to the same event. Long-running PHP processes use event loops (ReactPHP, Amp) to handle I/O events asynchronously.
Previous
What is middleware in PHP frameworks?
Next
What is Command Query Responsibility Segregation (CQRS) in PHP?