PHP and Laravel interview questions and answers
PHP still runs a large share of the web’s websites and products. Interviews cover core PHP, security, Laravel or WordPress, and databases.
12 questions. Read each one, start the timer and answer out loud as if you were in the room, then open the tip. Nothing is recorded.
What is the difference between include and require?
What a good answer covers
require stops with a fatal error if the file is missing; include only warns. The _once versions load a file only once.
What is the difference between == and ===?
What a good answer covers
== compares after type juggling. === compares value and type, and is safer.
How do you prevent SQL injection in PHP?
What a good answer covers
Prepared statements with PDO or the framework’s query builder. Never put user input straight into SQL.
How do you store passwords?
What a good answer covers
password_hash() to store and password_verify() to check. Never MD5 or SHA1.
What are sessions and cookies?
What a good answer covers
A cookie is stored in the browser. A session stores data on the server, linked to the browser by a session cookie.
What is Composer?
What a good answer covers
PHP’s dependency manager. It installs packages and sets up autoloading from composer.json.
Explain MVC in Laravel.
What a good answer covers
Routes point to controllers, controllers use Eloquent models for data and return Blade views.
What are traits?
What a good answer covers
A way to reuse methods across classes without inheritance.
What changed in PHP 8?
What a good answer covers
Named arguments, match, the nullsafe operator, union types, attributes and JIT. 8.1 added enums and readonly properties.
How do you prevent XSS and CSRF?
What a good answer covers
Escape output with htmlspecialchars, and check a CSRF token on every form that changes data.
How do you speed up a slow PHP site?
What a good answer covers
Turn on OPcache, fix slow queries with indexes, cache results and pages, and serve static files from a CDN.
Have you built WordPress themes or plugins?
What a good answer covers
Explain hooks: actions run code at points, filters change data. Mention a plugin you built or customised.
All 12 questions with answers
1. What is the difference between include and require?
require stops with a fatal error if the file is missing; include only warns. The _once versions load a file only once.
2. What is the difference between == and ===?
== compares after type juggling. === compares value and type, and is safer.
3. How do you prevent SQL injection in PHP?
Prepared statements with PDO or the framework’s query builder. Never put user input straight into SQL.
4. How do you store passwords?
password_hash() to store and password_verify() to check. Never MD5 or SHA1.
5. What are sessions and cookies?
A cookie is stored in the browser. A session stores data on the server, linked to the browser by a session cookie.
6. What is Composer?
PHP’s dependency manager. It installs packages and sets up autoloading from composer.json.
7. Explain MVC in Laravel.
Routes point to controllers, controllers use Eloquent models for data and return Blade views.
8. What are traits?
A way to reuse methods across classes without inheritance.
9. What changed in PHP 8?
Named arguments, match, the nullsafe operator, union types, attributes and JIT. 8.1 added enums and readonly properties.
10. How do you prevent XSS and CSRF?
Escape output with htmlspecialchars, and check a CSRF token on every form that changes data.
11. How do you speed up a slow PHP site?
Turn on OPcache, fix slow queries with indexes, cache results and pages, and serve static files from a CDN.
12. Have you built WordPress themes or plugins?
Explain hooks: actions run code at points, filters change data. Mention a plugin you built or customised.
Before the interview
- Read the job description twice and match two of your examples to what it asks for.
- Keep printed copies of your resume, ID proof and certificates ready, even for online rounds.
- Know your current CTC, expected salary and notice period. Check typical pay in our salary guide, and compare offers with the in-hand salary calculator.
- Genuine employers never ask you to pay for an interview, training kit or joining. Report anyone who does.