The right PHP interview questions make the technical interview a decisive moment in your hiring process, because you need to ask the right things to find the ideal candidate. Besides choosing good questions, you can decide whether to test during screening or after the first interview. This guide brings together 50 technical questions on PHP and Laravel to help you along the way.
Before we start, remember that PHP, together with Laravel, is one of the most widely used technologies for server-side web development. Rasmus Lerdorf created the PHP language in 1994.
Although it has been around for decades, it is still in high demand. Its advantages include being a scripting language with simple syntax, running on every major platform, working alongside HTML, and making plugin development easy. You can learn more in the official PHP documentation.
Several frameworks appeared to make the most of PHP, such as CakePHP and CodeIgniter in the mid-2000s. Laravel arrived in 2011 and brought more robustness and simplicity to the language. It is based on the MVC (model, view, controller) architecture and on code reuse.
Laravel’s benefits include a simple, concise syntax, a modular system with a dependency manager, and access to relational databases. The framework keeps code clean and makes teamwork easier. That is why its tagline is “the PHP framework for web artisans.”
All of this makes the PHP/Laravel developer an important part of many teams, especially at companies with web products, e-commerce, and internal systems.
Now that you know a bit more about the technology, here are 50 questions for interviewing a PHP/Laravel developer.
Junior PHP interview questions
When interviewing a junior PHP/Laravel developer, the recruiter should assume they need to confirm the candidate’s grasp of the basics of both technologies: the language and the framework.
With that in mind, we selected 16 questions with short answers to give you a starting point.
1. What is PHP, and why is it used in web development?
PHP is a server-side programming language used mainly to build dynamic websites and web applications. It is popular for its simplicity, its flexibility, and its broad integration with databases and servers. It generates dynamic, interactive content inside HTML pages.
What to look for: that the candidate understands the difference between what runs on the server and what runs in the browser.
2. What is Laravel?
Laravel is an open-source PHP framework that makes it easier to build robust, scalable web applications. It offers routing, database migrations, and authentication, among other features, which simplifies common tasks and encourages clean, organized code.
What to look for: whether they mention projects where they used it and which parts of the framework they know well.
3. What is Composer in the PHP ecosystem?
Composer is PHP’s dependency manager. It installs, updates, and manages libraries and packages efficiently, and its autoloader loads those dependencies automatically, which ensures compatibility and speeds up development.
What to look for: whether they know composer.json and composer.lock and why the lock file belongs in version control.
4. What are migrations in Laravel?
Migrations are versioned scripts that create, change, or drop database tables in a controlled way. They make schema changes easy to track and help teams collaborate, and they run through Artisan commands to keep the database in sync with the code.
What to look for: whether they know how to roll back a migration and why editing migrations that already ran in production is a bad idea.
5. What is the difference between variables and constants in PHP?
Variables can change their value while the script runs, while constants keep a fixed value once defined. Constants are declared with define() or const and do not use the $ symbol, unlike variables. They are ideal for values that never change, such as global settings.
What to look for: an example of when they would use a constant in a real project.
6. Which Laravel versions do you know, and how does its support policy work?
Laravel ships a major version roughly once a year. Under its support policy, each version gets bug fixes for 18 months and security fixes for 2 years. Recent versions require modern PHP versions and brought changes such as a leaner file structure.
What to look for: that they know which version they worked with and what changed when they upgraded. A candidate who has never upgraded a project has a gap worth exploring.
7. What is reverse routing?
Reverse routing is a Laravel feature that generates URLs from the names of the routes defined in code, for example with the route() helper. It keeps URLs consistent even when routes change, which reduces errors. It is useful for building links and redirects dynamically and reliably.
What to look for: whether they name their routes by habit and understand how that eases maintenance.
8. Can Laravel be used for full-stack development?
Yes. Laravel supports full-stack development with tools such as Livewire and Inertia.js, which let you build interactive, dynamic interfaces without relying only on a separate front-end framework.
What to look for: whether they know at least one of the two options and how they differ.
9. What does single inheritance mean in PHP?
Single inheritance means a class can inherit directly from only one other class. That limits inheritance to a linear hierarchy, but PHP offers traits to reuse code from several sources and partly work around the restriction.
What to look for: that they connect single inheritance to traits, which come up later in the interview.
10. Laravel is marketed to “web artisans.” Does that mean it can be used on the front end?
Laravel is often used with JavaScript frameworks such as Vue.js or React, which handle the dynamic, interactive side of the front end. “Web artisans” refers to the framework’s flexibility to build complete solutions, on both the back end and the front end, when combined with other technologies.
What to look for: that they separate what Laravel does (server, Blade templates) from what a front-end framework does.
11. Does Laravel support Bootstrap?
Yes. Laravel integrates easily with Bootstrap through packages such as Laravel UI, and its starter kits let you add a CSS framework to a project quickly. The most recent kits use Tailwind CSS by default.
What to look for: whether they know current kits default to Tailwind. It shows they know today’s ecosystem.
12. What is a session used for in Laravel?
A session stores temporary user data across HTTP requests. It keeps information such as login state or preferences while the user browses the site.
What to look for: whether they know session drivers (file, database, Redis) and when to change the default.
13. What does PEAR stand for?
PEAR (PHP Extension and Application Repository) is a repository of PHP packages and extensions that offered reusable libraries for common tasks, such as working with databases, sending email, or validating forms. Today it has been largely replaced by Composer and Packagist.
What to look for: that they know PEAR belongs to the past. If they recommend it for a new project, ask why.
14. Who are Laravel’s competitors?
In the PHP ecosystem, the main ones are Symfony, CodeIgniter, Yii, Laminas (formerly Zend Framework), Phalcon, CakePHP, and FuelPHP.
What to look for: whether they can compare Laravel with Symfony, the most common alternative on large projects.
15. What are the two main route files in Laravel?
Traditionally, web.php and api.php, inside the routes folder. In recent versions, api.php is no longer created by default and is added with php artisan install:api when the project exposes an API.
What to look for: whether they know about this recent change and the middleware differences between web and API routes.
16. Can PHP interact with HTML?
Yes. PHP runs on the server and generates dynamic HTML that is sent to the browser. It can insert data into HTML pages, for example to show database content, process forms, or work with variables, which makes pages dynamic.
What to look for: that they understand the browser only ever receives the final HTML, never the PHP code.
These answers show how well the candidate knows PHP and Laravel fundamentals. At this level, you can use the questions before the technical interview to filter the strongest candidates and move forward with them.
Next come questions for more experienced profiles, which call for more complexity and reasoning.
Mid-level PHP interview questions
A mid-level PHP/Laravel role should go to someone with about two to five years of experience and deeper knowledge of the framework. Here are the key questions for this level.
17. What is middleware in Laravel, and how would you use it in a project?
Middleware is a layer of code between the request and the response that lets you run logic before or after the request is handled. It is used for authentication, permission checks, and access control, among other tasks, to protect routes and transform data.
What to look for: a concrete example of middleware the candidate wrote.
18. What are resource routes?
Resource routes are predefined routes that make it easier to build RESTful controllers. They automatically map common actions (index, create, store, show, edit, update, and destroy) to controller methods. With Route::resource(), building APIs or CRUDs is faster and the code stays organized and consistent.
What to look for: whether they know Route::apiResource() for APIs, which skips the form routes.
19. How do you set up routes in Laravel?
Routes are defined in routes/web.php for the web and in routes/api.php for APIs. You use methods such as Route::get(), Route::post(), or Route::put() to map URLs to functions or controllers. For resources, Route::resource() generates a controller’s CRUD routes automatically.
What to look for: whether they know route groups, prefixes, and middleware applied to groups.
20. How does the Eloquent ORM make working with databases easier in Laravel?
Eloquent lets you work with tables as if they were objects. It offers a simple syntax for CRUD operations such as create(), update(), delete(), and find(), without writing SQL by hand. It also supports relationships between tables, such as hasMany and belongsTo, which makes data handling more intuitive and efficient.
What to look for: whether they know the N+1 problem and how to fix it with eager loading (with()).
21. How does the Blade templating engine work in Laravel?
Blade is Laravel’s templating engine for building dynamic, reusable layouts simply. It uses directives such as @if, @foreach, @include, and @yield inside HTML, and it supports layout inheritance, so you can create a base page structure and reuse common parts. It also supports components.
What to look for: whether they know Blade components and automatic output escaping.
22. How do you manage configuration files in a Laravel application?
Configuration files live in the config directory, each one grouping the settings for one part of the application. You read them with the config() helper, for example config(‘app.timezone’). The .env file defines environment variables for development, testing, and production.
What to look for: that they know .env stays out of version control and that configuration should be cached in production.
23. Which databases does Laravel support?
It supports several databases, including MySQL, MariaDB, PostgreSQL, SQLite, and SQL Server. Other databases can be connected through additional drivers.
What to look for: real experience with at least one of them and with moving between engines.
24. What are traits?
Traits are a PHP mechanism for code reuse: they let several classes share methods without inheritance. They help avoid duplication and add common behavior to different classes.
What to look for: whether they can resolve method conflicts between two traits and know when a trait becomes a design smell.
25. Which kinds of arrays does PHP support?
PHP supports two main kinds of arrays: indexed and associative. It also supports multidimensional arrays, meaning arrays that contain other arrays.
What to look for: examples of useful array functions, such as array_map, array_filter, or array_key_exists.
26. What is the goto statement for?
goto changes the flow of execution by jumping straight to a point in the code marked with a label. However, it can make code hard to read and maintain. Loops and conditionals are the better choice for clear, organized control flow.
What to look for: that they recognize it should almost never be used.
27. How would you hash a password in PHP?
With password_hash(), which uses bcrypt by default and produces a secure hash. To check a password, you use password_verify(). In Laravel, the Hash facade handles this.
What to look for: that they never suggest MD5 or SHA1 for passwords.
28. How do you set up soft deletes?
A soft delete marks a record as deleted without removing it from the database. It relies on a deleted_at column in the table, and you enable it by adding the SoftDeletes trait to the model.
What to look for: whether they know how to query deleted records with withTrashed() and restore them.
29. What are the steps to create middleware?
First, create it with php artisan make:middleware MiddlewareName. Then implement the logic. Next, register it (in recent versions in bootstrap/app.php, in older ones in the Kernel), and finally apply it to routes or groups.
What to look for: whether they know where registration moved in recent versions.
30. Which class do you use to handle exceptions?
Exceptions are handled through the Exception class and its subclasses. To handle specific exceptions, older versions used app/Exceptions/Handler.php, whose render() method defines the response to the user. In recent versions, exception handling is configured in bootstrap/app.php with withExceptions().
What to look for: whether they log and report errors with context, not just display them.
31. What does the crypt() function do?
crypt() hashes a string and was used for years to store passwords. It relies on algorithms such as DES, Blowfish, or SHA-512, depending on the system. It is not recommended for new projects, because password_hash() and password_verify() are safer and simpler.
What to look for: that they recommend the modern functions.
32. Explain dependency injection.
Dependency injection is a design pattern in which a class receives its dependencies from outside instead of creating them itself. It improves flexibility, makes testing easier, and reduces coupling between components.
What to look for: that they connect it to Laravel’s service container, which comes up in the senior questions.
33. How would you create a sitemap.xml in Laravel?
The usual route is a package such as spatie/laravel-sitemap. You install it with Composer, write a command or task that adds the URLs, and schedule it to generate sitemap.xml in the public folder. You can also build it by hand with a route that returns XML.
What to look for: whether they think of automating generation with Laravel’s scheduler.
A mid-level PHP/Laravel developer should handle these concepts and commands comfortably. With these questions and their expected answers, you can filter the best candidates. If you are hiring a senior profile, pay attention to the questions below.
Validate PHP and Laravel skills with a hands-on challenge first
Questions show how a candidate thinks, but a coding challenge shows how they work: how they organize routes, controllers, and models, and how they write tests. Running a technical assessment before the interview lets you walk in with evidence.
Try Coodesh technical assessments free
Senior PHP interview questions
When interviewing a senior PHP/Laravel developer, keep in mind that they will hold a strategic position on the team and work on complex software projects.
They should have solid PHP and Laravel experience, strong object-oriented programming (OOP) skills, advanced knowledge of web services (REST and SOAP), and experience with databases such as PostgreSQL or MySQL. Here are the questions for this level.
34. How would you implement caching in a Laravel application to improve performance?
Laravel has a built-in cache system, configured in config/cache.php, with drivers such as Redis or Memcached. In code, you use helpers such as Cache::remember() to store expensive results for a period of time. In production, you also cache configuration, routes, and views with commands such as php artisan config:cache and route:cache.
What to look for: that they talk about cache invalidation and how they chose what to cache.
35. Explain how you would use jobs and queues in Laravel for asynchronous work.
Jobs and queues let you process slow tasks asynchronously and improve performance. You create a job with php artisan make:job ProcessTask, configure a queue in config/queue.php (for example Redis or the database), dispatch the job with dispatch(), and process it with the php artisan queue:work worker.
What to look for: whether they know retries, failed jobs, and how to monitor workers in production.
36. What is Laravel’s service container, and how does it support dependency injection?
The service container is Laravel’s dependency manager: it resolves classes and interfaces automatically. You register services with bind() or singleton() and they are resolved when classes are instantiated through the constructor or a method. That reduces coupling and improves maintainability.
What to look for: whether they know how to bind an interface to an implementation and why that makes testing easier.
37. Describe how you use events and listeners in Laravel to build decoupled applications.
Events and listeners let you react to specific actions in an organized, decoupled way. You fire an event with event() or the event’s dispatch method, and the associated listeners run the response logic. You create them with php artisan make:event and make:listener; recent versions discover them automatically, while older ones registered them in EventServiceProvider.
What to look for: whether they know queued listeners, which avoid blocking the request.
38. How would you protect a Laravel application against common attacks such as SQL injection and XSS?
Against SQL injection, use Eloquent or parameterized queries with the query builder. Against XSS, output data in Blade with {{ $data }}, which escapes the content, instead of {!! $data !!}. Also enable CSRF protection and validate user input.
What to look for: whether they also mention authorization (policies), rate limiting, and safe handling of file uploads.
39. Describe what Memcached is.
Memcached is a distributed caching system that keeps data in RAM for fast access. It improves performance by cutting repeated database queries. In Laravel, you can set it as the cache driver in config/cache.php.
What to look for: whether they can compare Memcached with Redis and explain when they would choose each.
40. How do you validate requests?
With a FormRequest class or the validate() method. You create a custom request with php artisan make:request, define rules in its rules() method, and use it in the controller. You can also validate directly in the controller with $request->validate([‘field’ => ‘rule’]). That way data arrives clean and safe.
What to look for: whether they prefer FormRequest on large projects and can explain why.
41. What is the difference between the register and boot methods?
In a service provider, register is for binding services into the container (bindings and singletons). boot runs after every service has been registered and is where you configure events, middleware, or logic that depends on other services.
What to look for: that they know why you should not use other services inside register.
42. Explain what a lambda function does.
In PHP, a lambda is an anonymous function that lets you store or pass blocks of code as variables. You create it with an unnamed function and can assign it to a variable or pass it as an argument. PHP also has arrow functions (fn() =>), which capture variables from the surrounding scope automatically.
What to look for: whether they know the use keyword in closures and how it differs from arrow functions.
43. How does a facade work, and how do you mock it in tests?
A facade provides static-style access to services in the container. You create a class with a getFacadeAccessor() method that returns the name of the registered service. In tests, Laravel lets you mock facades with methods such as shouldReceive() or fake().
What to look for: experience writing tests with faked facades, such as Mail::fake() or Queue::fake().
44. What are Laravel guards?
Guards handle user authentication: they define how credentials are checked and stored. Laravel ships with guards such as web (session-based) and supports API tokens, for example through Sanctum. You can define your own guards in config/auth.php, each with its own driver.
What to look for: whether they separate authentication (guards) from authorization (gates and policies).
45. Give two examples of PHP magic methods.
__construct(), the class constructor, which runs when an instance is created, and __get(), which runs when you access properties that do not exist or are not accessible.
What to look for: whether they know where Laravel relies on magic methods, for example for Eloquent attributes.
46. Does PHP support typecasting?
Yes. PHP lets you convert one data type into another explicitly, either with casting, such as (int) or (string), or with conversion functions such as intval().
What to look for: whether they know type declarations and strict_types, the other side of the topic in modern PHP.
47. In Laravel, how do you remove a compiled class file?
With php artisan clear-compiled, which deletes compiled class files and related caches so Laravel regenerates them on the next run.
What to look for: whether they also know optimize:clear, which clears several caches at once.
48. How do you open a file in PHP?
With fopen(), which lets you set the mode, such as read, write, or append. In Laravel, the usual approach is the Storage facade, which abstracts local or cloud file systems.
What to look for: whether they know Storage and handle errors when working with files.
49. What does propagating a session ID mean?
It means passing a user’s unique session identifier across pages or requests in a web application to keep their state, such as login or preferences. PHP can do this with cookies or through the URL, but passing the ID in the URL is insecure and opens the door to attacks such as session fixation, so cookies are the standard.
What to look for: that they spot the security risk of passing the ID in the URL.
50. Explain what soundex() does.
The soundex() function produces a phonetic representation of a string: it turns a word into a code that reflects how it sounds, regardless of spelling differences. It is useful for comparing words that sound alike but are spelled differently. It was designed for English.
What to look for: general knowledge of the language. It works as a closing question.
How to use these PHP interview questions
With the right questions, a recruiter can find the best PHP/Laravel developer for the project. It is just as important to choose the right moment to use them. Here are our tips.
Match questions to the candidate’s level: besides picking questions for junior, mid-level, and senior candidates, evaluate the answers according to seniority. Senior candidates should give fuller, deeper answers, so it helps to involve the tech lead in the evaluation.
Know what to look for in the answers: at the start of the process, the recruiter should align with the engineering team. Depending on the project and seniority, you will weigh conceptual knowledge, hands-on experience, problem solving, or delivery more heavily.
Ask for practical solutions: besides technical questions, you can include practical tests in the process, such as live coding, bug fixing, or building a small project. If you are unsure when to run them, see our guide on running a pre-employment assessment before or after the interview.
Practical scenarios to assess PHP and Laravel
You can also set practical scenarios, such as building a simple CRUD with routes, controllers, and Eloquent. Since the candidate also needs to know databases well, you can ask them to write a migration for related tables and use them through Eloquent.
Either way, tailor the exercises to what the candidate will face day to day at your company. Recruiting and engineering should stay aligned throughout. A good starting point is a briefing meeting with the tech lead to define the job description and the questions.
Related reading
- Python Backend Interview Questions: 30 Questions by Level
- C# Interview Questions: 50 Questions and Answers by Level
- Online Coding Tests: A Strategic Way to Assess Developers
- Coodesh technical assessments: coding challenges, SQL, QA, and more
Conclusion
As you have seen, interviewing PHP/Laravel developers is a key step toward a successful hiring process, alongside other stages such as technical tests and the culture fit interview.
Still, the quality and depth of the questions in the technical interview make the difference when choosing the right candidate. Recruiters can steer the questions toward the company’s needs and keep the best-prepared candidates.
With this list of 50 PHP interview questions, you can kick off your hiring process. Beyond the technical interview, build tests tailored to your role.
Assess PHP and Laravel developers on evidence
Coodesh lets you run technical assessments asynchronously, with scoring inside the platform and support from artificial intelligence, so you can compare candidates with data.
Try Coodesh technical assessments free
Large company or custom needs? Book a demo with our team.


