8 role-specific questions
PHP Developer Interview Questions & Answers
PHP interviews today focus on modern PHP 8 and frameworks like Laravel: typed code, the request lifecycle, Eloquent performance, security and testing.
Free, no sign-up. 91 questions in this role's practice pool, including behavioural, HR and situational questions.
PHP & Laravel interview questions
Modern PHP, Laravel, security, performance and testing.
1.
What features of modern PHP (8.x) do you use, and why?
BeginnerTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Whether you write current PHP rather than legacy-style code.
Key points a strong answer covers
- Types. Scalar, union and return types with strict_types.
- Language features. match, named arguments, constructor property promotion, readonly, enums, nullsafe operator, attributes.
- Performance. OPcache (and JIT for CPU-heavy code).
- Tooling. Composer, PSR standards and static analysis like PHPStan.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Describing PHP 5-era practices.
- No mention of static analysis or types.
Likely follow-up questions
- What does
declare(strict_types=1)change? - How do enums improve code over class constants?
Example strong answer
I write PHP 8 with
declare(strict_types=1)and full type declarations — union and nullable types, return types — so many bugs surface early, and I run PHPStan at a high level in CI. Day to day I use constructor property promotion andreadonlyproperties for compact immutable value objects, native enums instead of class constants,matchinstead of long switches because it's strict and returns a value, named arguments for clarity, and the nullsafe operator?->. Attributes replace docblock annotations for things like routing. Composer manages dependencies with PSR-4 autoloading, and OPcache is enabled in production.2.
Walk through the lifecycle of a request in Laravel.
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Framework depth beyond tutorials.
Key points a strong answer covers
- Entry point. Requests enter through public/index.php, which bootstraps the app.
- Service container & providers. Service providers register and boot services in the container.
- Middleware. The request passes through global and route middleware.
- Routing to controller. The router dispatches to a controller (with form request validation).
- Response. A response (view, JSON resource) travels back through middleware.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Not knowing what service providers do.
- Skipping middleware.
Likely follow-up questions
- What's the difference between register() and boot() in a service provider?
- Where would you put authorisation logic?
Example strong answer
Every request enters through
public/index.php, which loads Composer's autoloader and bootstraps the application. The service container is created and service providers run: first each provider'sregistermethod binds services into the container, thenbootruns once everything is registered. The HTTP kernel sends the request through global middleware — maintenance mode, trimming strings, sessions, CSRF — then the router matches a route and applies its middleware, likeauth. The controller is resolved from the container with its dependencies injected; a form request can validate and authorise before the method runs. The controller returns a view, an API resource or a response, which passes back out through the middleware to the client.3.
How do you avoid performance problems with Eloquent?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
ORM performance awareness.
Key points a strong answer covers
- N+1 / eager loading. Eager-load relationships with with() to avoid N+1 queries.
- Select only needed. Select only needed columns.
- Large datasets. Chunk, lazy collections or cursor for large sets; paginate.
- Indexes & detection. Indexes, and detect issues with Telescope/Debugbar or Model::preventLazyLoading().
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Loading thousands of models with ->get() and looping.
- Lazy loading relations inside Blade loops.
Likely follow-up questions
- What does
Model::preventLazyLoading()do? - When would you use the query builder instead of Eloquent?
Example strong answer
The most common issue is N+1 queries — looping over posts in a Blade view and touching
$post->authorruns a query per post — so I eager-load withPost::with('author'), and in development I enableModel::preventLazyLoading()so it throws instead of silently querying. I select only the columns I need and usewithCountinstead of loading relations just to count them. For large jobs I process records withchunkByIdorlazy()instead of loading everything withget(), and list endpoints are paginated. I check queries with Telescope or Debugbar, add indexes for common filters, and drop to the query builder or raw SQL for heavy reports.4.
How do you protect a PHP/Laravel application against common attacks?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Web security fundamentals in PHP.
Key points a strong answer covers
- SQL injection. Prepared statements / Eloquent bindings; never concatenate input.
- XSS. Blade's {{ }} escapes output; avoid {!! !!} with user input.
- CSRF. CSRF tokens on forms (Laravel's @csrf).
- Mass assignment. Use $fillable and validated data to prevent mass assignment.
- Passwords / auth. password_hash/Hash::make, rate-limit logins.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Passing $request->all() into create().
- Echoing user content with {!! !!}.
Likely follow-up questions
- What is mass assignment and how does $fillable prevent it?
- How would you securely handle file uploads?
Example strong answer
For SQL injection I only use Eloquent, the query builder or PDO prepared statements with bound parameters — never string-concatenated input, including in
whereRaw. For XSS, Blade's{{ }}escapes output, and I avoid{!! !!}with anything user-controlled, sanitising rich text if needed. Laravel's CSRF middleware and the@csrfdirective protect forms. I prevent mass assignment by defining$fillableand passing$request->validated()rather than$request->all(). Passwords are hashed withHash::make, login routes are throttled, and authorisation uses policies. Uploaded files are validated by type and size, stored outside the web root, and never executed.5.
How do queues and jobs work in Laravel, and when do you use them?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Background processing design.
Key points a strong answer covers
- Dispatch jobs. Jobs implement ShouldQueue and are dispatched to a queue.
- Drivers & workers. Workers (queue:work, Horizon) process jobs from Redis, SQS or the database.
- Failures & retries. Configure tries, backoff and timeouts; failed jobs are recorded.
- Use cases. Emails, notifications, imports, image processing — anything slow.
- Idempotency. Jobs should be idempotent; use unique jobs where needed.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Running queue workers without a process monitor.
- Passing huge models into jobs.
Likely follow-up questions
- What happens to a running job when you deploy new code?
- How does Horizon help?
Example strong answer
A job is a class implementing
ShouldQueuewith ahandlemethod; callingdispatchserialises it onto a queue — Redis, SQS or the database — and workers started withqueue:workand kept alive by Supervisor, or Horizon for Redis, pick it up. I move anything slow out of the request: sending emails and notifications, importing CSVs, resizing images, calling slow third-party APIs. Each job definestries,backoffand atimeout; failures land infailed_jobsfor inspection and retry. Because a job can run more than once, I make them idempotent, and I pass model ids rather than huge payloads. Workers need restarting on deploy withqueue:restartso they load new code.6.
How do you test a Laravel application?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Testing practice in PHP.
Key points a strong answer covers
- PHPUnit / Pest. PHPUnit or Pest.
- Feature tests. Feature tests make HTTP requests and assert responses.
- Database. RefreshDatabase and model factories set up data.
- Fakes. Facade fakes (Mail, Queue, Http) instead of hitting real services.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Tests depending on seeded production-like data.
- Calling real APIs in tests.
Likely follow-up questions
- What does Http::fake() let you assert?
- How do you test an authorised vs unauthorised request?
Example strong answer
I use Pest or PHPUnit. Most value comes from feature tests that make real HTTP requests to the app —
$this->actingAs($user)->postJson('/api/orders', $data)— then assert the status, the JSON and the database state withassertDatabaseHas.RefreshDatabaseresets the database between tests, and model factories create exactly the data each test needs. External effects are faked:Mail::fake(),Queue::fake()andHttp::fake()let me assert that an email was queued or an API was called with certain data, without sending anything. Unit tests cover pure business logic, and everything runs in CI with static analysis.7.
How do sessions and authentication work in PHP?
BeginnerTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Web fundamentals: how a login is remembered, and how to keep it secure.
Key points a strong answer covers
- Session id cookie. PHP stores session data server-side and gives the browser a session id cookie.
- Session storage. Data lives in files, Redis or the database.
- Security. Regenerate the id on login, use httpOnly/Secure/SameSite cookies.
- Laravel auth. Laravel guards, Sanctum for SPAs/APIs, starter kits.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Not regenerating the session id after login.
- Storing sessions in files across multiple servers.
Likely follow-up questions
- What is session fixation?
- How would you authenticate a mobile app against a Laravel API?
Example strong answer
PHP sessions keep data on the server and give the browser a random session id in a cookie. On each request PHP reads the cookie and loads the matching data from storage — files by default, but Redis or the database when you run several servers. For security I regenerate the session id at login to prevent session fixation, set the cookie as httpOnly, Secure and SameSite, and expire idle sessions. In Laravel, guards handle authentication: the session guard for web pages, and Sanctum for SPAs — using the same cookie session — or mobile apps with personal access tokens. Starter kits like Breeze provide login, registration and password reset.
8.
How would you improve the performance of a slow PHP application?
AdvancedTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Measured optimisation.
Key points a strong answer covers
- Measure. Profile first (Blackfire, Xdebug, APM).
- OPcache / config. Enable OPcache and Laravel's config/route caching.
- Database. Fix slow queries and N+1s.
- Caching. Cache expensive results in Redis.
- Offload / scale. Queue slow work; tune PHP-FPM; consider Octane.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Guessing instead of profiling.
- Forgetting OPcache in production.
Likely follow-up questions
- What does OPcache do?
- What does Laravel Octane change about the request lifecycle?
Example strong answer
I'd measure first with an APM or a profiler like Blackfire to see whether time goes to PHP, the database or external calls. The quick wins: make sure OPcache is enabled and sized properly, and in Laravel run
config:cache,route:cacheandview:cacheon deploy with an optimised autoloader. Then the database — usually the biggest factor — fixing N+1 queries with eager loading, adding indexes and paginating. Expensive computations and API responses get cached in Redis with sensible invalidation. Slow work moves to queues. Finally, tune PHP-FPM worker counts, and for high-traffic apps consider Laravel Octane, which keeps the app in memory between requests — while watching for state leaking between requests.
Ready to answer them out loud?
Run a timed php developer mock interview, type or speak your answers, and get a score breakdown with what to improve.