AI
prepair.app
Start interview →
EnglishРусскийУкраїнська
🐘

Junior PHP BackendPHP interview questions

Junior · no experience / under 1 year

PHP interviews cover language semantics, OOP, Laravel or Symfony, MySQL, and web security basics. Below are the most common questions with model answers. Junior: core theory, definitions, and simple practical cases.

Topics to prepare

OOP and SOLID in PHP
Laravel / Symfony
MySQL and query optimization
Composer and autoloading
Sessions, cookies, security
PSR standards

7 Junior-level questions with answers

1

What is the difference between == and === in PHP?

Answer

== compares values after type juggling, while === also requires the types to match. Loose comparison produces famous surprises: "abc" == 0 was true before PHP 8, and "1e2" == "100" is still true because both look numeric. The rule in production code is to always use === unless you have a specific reason not to.

2

What are traits? How do they differ from inheritance and interfaces?

Answer

A trait is a block of methods and properties that can be composed into a class, working around PHP's single inheritance. An interface declares a contract with no implementation; inheritance gives an is-a relationship with one parent; a trait gives reusable implementation without a type relationship. Conflicts between traits must be resolved explicitly with insteadof or as.

3

Explain the SOLID principles with PHP examples.

Answer

Single Responsibility: a class has one reason to change, so a controller does not also build PDFs. Open/Closed: extend behaviour through new classes rather than editing existing ones. Liskov: a subclass must be usable wherever the parent is. Interface Segregation: many small interfaces beat one fat one. Dependency Inversion: depend on interfaces injected into the constructor, not on concrete classes created with new.

4

What is the Dependency Injection Container in Laravel and how does it work?

Answer

The container resolves class dependencies automatically by reflecting on constructor type hints and instantiating what is needed recursively. You bind interfaces to concrete implementations in a service provider, so swapping an implementation is a one-line change. Singleton bindings share one instance per request lifecycle, which matters for stateful services like a connection pool.

5

How do you protect against SQL injection? What are prepared statements?

Answer

A prepared statement sends the SQL structure and the parameters separately, so user input is never parsed as SQL and quoting mistakes cannot become an injection. In PHP that means PDO or mysqli with bound parameters, or an ORM that does it for you. String concatenation into a query is the vulnerability; escaping functions are a fragile substitute because they depend on charset and context.

6

What is Eloquent ORM? Explain the N+1 problem and how to solve it.

Answer

Eloquent is Laravel's active-record ORM where each model maps to a table and relationships are defined as methods. N+1 happens when you loop over models and touch a relation, firing one query per row. The fix is eager loading with with(), and you can catch it in development by enabling Model::preventLazyLoading() so a lazy access throws instead of silently degrading.

7

What is middleware in Laravel? Give a usage example.

Answer

Middleware wraps the HTTP request pipeline, letting you run code before or after the controller — authentication, rate limiting, CORS headers, logging. Each middleware receives the request and a $next closure, decides whether to pass it along, and can modify the response on the way back. Because it composes, cross-cutting concerns stay out of controllers.

🦎

Reading answers is not enough

In a real interview you speak under pressure. Cam asks these same questions, scores every answer, and shows exactly what to fix.

Practice a Junior PHP Backend interview →
Free · 3 interviews per month

Other levels — PHP Backend

Middle PHP BackendSenior PHP BackendAll PHP Backend questions

Other specializations

🔍Junior Manual QA🤖Junior QA AutomationJunior Java Backend🐍Junior Python Backend🦫Junior Go Backend🟢Junior Node.js Backend⚛️Junior React Frontend💚Junior Vue Frontend🅰️Junior Angular FrontendJunior Next.js