PHP 7 interview question · Most asked
Explain the MVC pattern as used in PHP frameworks.
Summary
MVC separates the Model (data and business rules), the View (presentation templates) and the Controller (handles the HTTP request, calls models/services, chooses a view).
Longer Answer
A front controller (public/index.php) receives every request, a router maps it to a controller action, and the response is rendered. Keep controllers thin by moving business logic into services or domain models, so it can be reused from CLI or queues.
Key Points
- Front controller + router
- Thin controllers
- Business logic in models/services
- Views only format output
More most-asked PHP 7 questions
- What are typed properties in PHP 7.4?
- How do return type declarations work in PHP 7?
- What were the headline improvements of PHP 7.0 over PHP 5.6?
- Explain scalar type declarations and coercive vs strict mode in PHP 7.
- Explain the `Throwable`, `Error` and `Exception` hierarchy introduced in PHP 7.
- What are nullable types in PHP 7.1?
- What does the null coalescing operator `??` do, and how is it different from `isset()` with a ternary?
- What are arrow functions in PHP 7.4 and how do they differ from closures?