Skip to content
Resume Studioby M2Toolkit

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. 1.

    What features of modern PHP (8.x) do you use, and why?

    BeginnerTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 and readonly properties for compact immutable value objects, native enums instead of class constants, match instead 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.

    Practise this question and get feedback
  2. 2.

    Walk through the lifecycle of a request in Laravel.

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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's register method binds services into the container, then boot runs 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, like auth. 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.

    Practise this question and get feedback
  3. 3.

    How do you avoid performance problems with Eloquent?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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->author runs a query per post — so I eager-load with Post::with('author'), and in development I enable Model::preventLazyLoading() so it throws instead of silently querying. I select only the columns I need and use withCount instead of loading relations just to count them. For large jobs I process records with chunkById or lazy() instead of loading everything with get(), 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.

    Practise this question and get feedback
  4. 4.

    How do you protect a PHP/Laravel application against common attacks?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 @csrf directive protect forms. I prevent mass assignment by defining $fillable and passing $request->validated() rather than $request->all(). Passwords are hashed with Hash::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.

    Practise this question and get feedback
  5. 5.

    How do queues and jobs work in Laravel, and when do you use them?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 ShouldQueue with a handle method; calling dispatch serialises it onto a queue — Redis, SQS or the database — and workers started with queue:work and 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 defines tries, backoff and a timeout; failures land in failed_jobs for 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 with queue:restart so they load new code.

    Practise this question and get feedback
  6. 6.

    How do you test a Laravel application?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 with assertDatabaseHas. RefreshDatabase resets the database between tests, and model factories create exactly the data each test needs. External effects are faked: Mail::fake(), Queue::fake() and Http::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.

    Practise this question and get feedback
  7. 7.

    How do sessions and authentication work in PHP?

    BeginnerTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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.

    Practise this question and get feedback
  8. 8.

    How would you improve the performance of a slow PHP application?

    AdvancedTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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:cache and view:cache on 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.

    Practise this question and get feedback

Behavioural & HR questions you'll also get

These come up in almost every php developer interview. Story questions are best answered with STAR — Situation, Task, Action, Result.

  • Tell me about yourself.

    BeginnerHR

    What the interviewer is evaluating

    Whether you can give a concise, relevant pitch that frames your experience around this job.

    Key points a strong answer covers

    • Present. Start with your current role and what you do.
    • Relevant past. Pick the most relevant past experience.
    • Strength / achievement. Include one strength or achievement with evidence.
    • Why this role. Finish with why this role is the next step.

    Suggested answer structure

    1. Present — your current role in one or two sentences.
    2. Past — the experience most relevant to this job.
    3. Proof — one achievement or strength with evidence.
    4. Future — why this role is the logical next step.

    Common mistakes

    • Reciting your whole CV chronologically.
    • Personal life story unrelated to the job.
    • Going over two minutes.

    Likely follow-up questions

    • Why are you looking to leave your current role?
    • What would your manager say is your biggest strength?
    Example strong answer

    I'm a front-end developer with four years' experience, currently at a fintech start-up where I build the customer dashboard in React and TypeScript. Before that I spent two years at an agency building e-commerce sites, which taught me to work fast with lots of different clients. The thing I'm proudest of recently is leading our move to a shared component library, which cut the time to build new screens by about a third. I'm now looking for a role where I can work on a larger product with a strong design system, which is exactly what drew me to this position.

  • Why should we hire you?

    BeginnerHR

    What the interviewer is evaluating

    Whether you understand the role and can match your strengths to its needs with evidence.

    Key points a strong answer covers

    • Role's needs. Show you understand what the role needs.
    • Matching strengths. Match two or three strengths to those needs.
    • Evidence. Back each with evidence.
    • Enthusiasm. Close with genuine enthusiasm.

    Suggested answer structure

    1. Name the two or three things the role needs most.
    2. Match each with your experience and evidence.
    3. Add what makes you different.
    4. Finish with genuine interest.

    Common mistakes

    • Generic claims like 'I'm hardworking' with no evidence.
    • Comparing yourself to other candidates you don't know.

    Likely follow-up questions

    • What would you do in your first 90 days?
    • What's one area where you'd need support?
    Example strong answer

    From the job description and our conversation, you need someone who can take ownership of the customer onboarding process, work with sales and product, and improve the numbers. I've done exactly that for three years: at my current company I redesigned onboarding for new accounts and cut the time to first value from 14 days to 6. I'm comfortable working across teams — I run a weekly session with sales and product on customer feedback — and I'm very data-driven, so I'd measure everything from day one. I'm also genuinely excited about your product, because it solves a problem I've seen customers struggle with.

  • Tell me about a time you disagreed with a teammate. How did you handle it?

    BeginnerBehavioural

    What the interviewer is evaluating

    Handling conflict constructively and keeping relationships.

    Key points a strong answer covers

    • Listened to their view. Show you listened to understand their view.
    • Used facts / common goal. Bring it back to facts or a shared goal.
    • Resolution & relationship. Resolve it and keep the relationship.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Making the other person the villain.
    • A story where you were simply right and they gave in.

    Likely follow-up questions

    • What if you couldn't reach agreement?
    • Have you ever been wrong in a disagreement?
    Example strong answer (a fictional story — use your own)

    On a website rebuild, a senior designer wanted an animated, image-heavy homepage, and I was worried it would hurt mobile load times and SEO. As the developer responsible for performance, I needed us to agree before the sprint started. I asked her to walk me through what she was trying to achieve — she wanted the brand to feel premium. I built two quick prototypes, one with her full design and one with lighter animations, and we tested both on a mid-range phone together. Hers took nearly six seconds to load. We agreed on a version that kept the key animation but lazy-loaded the rest. The page launched loading in under two seconds, and she later asked me to review designs earlier. I learned that testing together beats debating.

  • Tell me about a mistake you made and what you learned.

    BeginnerBehavioural

    What the interviewer is evaluating

    Honesty, accountability and learning.

    Key points a strong answer covers

    • Real mistake owned. Own a real mistake.
    • Fixed it. Show how you fixed it and who you told.
    • Changed behaviour. Show what you changed afterwards.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Choosing a fake mistake like 'I work too hard'.
    • Blaming others.

    Likely follow-up questions

    • How did your manager react?
    • How do you know you haven't repeated it?
    Example strong answer (a fictional story — use your own)

    In my first year as a marketing coordinator, I sent a promotional email to our whole list with the wrong discount code — I'd tested the email but not clicked the code itself. Within an hour customers were complaining that it didn't work. I told my manager immediately, set the wrong code to apply the discount too, and sent a short correction email with an apology. We lost very little revenue, and some customers replied thanking us for the quick fix. Since then I use a pre-send checklist that includes testing every link and code as a customer would, and I asked for a second person to check any campaign to more than 10,000 people.

  • Describe a situation where you worked under pressure or to a tight deadline.

    BeginnerBehavioural

    What the interviewer is evaluating

    Prioritisation, composure and delivery.

    Key points a strong answer covers

    • The pressure. Make the pressure concrete.
    • Prioritised. Show how you prioritised.
    • Communicated. Show how you kept people informed.
    • Delivered. Show the outcome.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Glorifying working all night as the solution.
    • No mention of prioritising.

    Likely follow-up questions

    • What would you do if it was clear you couldn't make the deadline?
    • How do you stop pressure affecting quality?
    Example strong answer (a fictional story — use your own)

    Two days before a client presentation, our analyst fell ill and I had to finish the market research report she'd been leading. I listed everything left and asked the account director which sections the client cared about most — pricing and competitor comparison. I focused on those, reused verified data from our previous report, and moved the appendix to a follow-up email. I sent a short update each evening so nobody was surprised. We delivered the core report on time, the client approved the next phase, and the appendix followed two days later. I learned to ask early what matters most rather than trying to do everything equally well.

  • What would you do if you realised you were going to miss a deadline?

    BeginnerSituational

    What the interviewer is evaluating

    Transparency and problem solving.

    Key points a strong answer covers

    • Tell people early. Flag it as soon as you know.
    • Assess the gap. Work out how far off you are.
    • Options. Offer options: reduced scope, help, a new date.
    • Prevent repeats. Learn why it happened.

    Suggested answer structure

    1. Clarify the situation and what's at stake.
    2. Say what you'd do first, and why.
    3. Explain who you'd involve and how you'd communicate.
    4. Describe how you'd check the outcome and prevent a repeat.

    Common mistakes

    • Waiting until the deadline to say anything.
    • Promising you'll just work all night.

    Likely follow-up questions

    • What if your manager is unavailable?
    • Has this happened to you?
    Example strong answer

    I'd tell the person depending on it as soon as I realised, not at the deadline. Before that conversation I'd work out how far off I am and why, so I could offer options: delivering the most important part on time and the rest a few days later, getting help from a colleague, or agreeing a new date. Then I'd let them decide what works best for them, and keep them updated. Afterwards I'd look at why it slipped — usually underestimating something — so I plan better next time.

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.

Interview questions for related roles