10 PHP Interview Questions and Answers You Should Know

Here are some PHP interview questions and answers for experienced developers (while also covering some beginner concepts).
Need to test a developer’s PHP skills, or have a PHP intreview coming up?
A few of the best developers within our network share their top PHP interview questions, answers, and interview tips to help test a developer’s PHP knowledge and expertise.
If you are the one interviewing PHP developers, keep in mind that you should also ask these interview questions about a developer’s experience and interview questions to test communication and management skills — or, just refer to our in-depth Guide to Hiring PHP Developers.
Without further ado, let’s jump in!

PHP Interview Tip #1
“One of the most important things I watch out is the creativity of the person I interview. I try to catch the developers who are constantly learning new things, they are driven by curiosity and also very creative, not just in problem solving but in general too. I mostly ask about PHP and PostgreSQL (I use this combo most of the time).” ~ Laszlo Levente Mári, ex-Googler
PHP Interview Question #1
What’s the difference between the include() and require() functions?
(Question provided by Laszlo Levente Mári)
They both include a specific file but on require the process exits with a fatal error if the file can’t be included, while include statement may still pass and jump to the next step in the execution.

PHP Interview Question #2
How can we get the IP address of the client?
(Question provided by Laszlo Levente Mári)
This question might show you how playful and creative the candidate is because there are many options. $_SERVER[“REMOTE_ADDR”]; is the easiest solution, but the candidate can write x line scripts for this question.

PHP Interview Question #3
What’s the difference between unset() and unlink()
(Question provided by Laszlo Levente Mári)
unset() sets a variable to “undefined” while unlink() deletes a file we pass to it from the file system.
PHP Interview Question #4
What is the output of the following code:
$a = ‘1’;
$b = &$a;
$b = “2$b”;
echo $a.”, “.$b;
PHP Developer Laszlo Levente Mári
Author Bio
Laszlo Levente Mári is an ex-Googler (front-end) and has taken several interview opportunities for fun. SitePoint Author, and full-stack developer at IDG where he is currently building the CMS of PCWorld.com. Hire Laszlo Now.

PHP Interview Tip #2

“During the interview of a potential candidate I am aiming to understand how updated they are with the new language features as well as their level of understanding of basic operations. In my opinion, this will define how good a developer will become in the future.” ~Agli Pançi, Lead Developer
PHP Interview Question #5
What are the main error types in PHP and how do they differ?
(Question provided by Agli Pançi)
In PHP there are three main type of errors:
Notices – Simple, non-critical errors that are occurred during the script execution. An example of a Notice would be accessing an undefined variable.
Warnings – more important errors than Notices, however the scripts continue the execution. An example would be include() a file that does not exist.
Fatal – this type of error causes a termination of the script execution when it occurs. An example of a Fatal error would be accessing a property of a non-existent object or require() a non-existent file.
Understanding the error types is very important as they help developers understand what is going on during the development, and what to look out for during debugging.

PHP Interview Question #6
What is the difference between GET and POST?
(Question provided by Agli Pançi)
GET displays the submitted data as part of the URL, during POST this information is not shown as it’s encoded in the request.
GET can handle a maximum of 2048 characters, POST has no such restrictions.
GET allows only ASCII data, POST has no restrictions, binary data are also allowed.
Normally GET is used to retrieve data while POST to insert and update.
Understanding the fundamentals of the HTTP protocol is very important to have for a PHP developer, and the differences between GET and POST are an essential part of it.

PHP Interview Question #7
How can you enable error reporting in PHP?
(Question provided by Agli Pançi)
Check if “display_errors” is equal “on” in the php.ini or declare “ini_set(‘display_errors’, 1)” in your script.
Then, include “error_reporting(E_ALL)” in your code to display all types of error messages during the script execution.
Enabling error messages is very important especially during the debugging process as one can instantly get the exact line that is producing the error and can see also if the script in general is behaving correctly.

PHP Interview Question #8
What are Traits?
(Question provided by Agli Pançi)
Traits are a mechanism that allows you to create reusable code in languages like PHP where multiple inheritance is not supported. A Trait cannot be instantiated on its own.
It’s important that a developer knows the powerful features of the language (s)he is working on, and Trait is one of such features.

PHP Interview Question #9
Can the value of a constant change during the script’s execution?
(Question provided by Agli Pançi)
No, the value of a constant cannot be changed once it’s declared during the PHP execution.

PHP Interview Question #10
Can you extend a Final defined class?
(Question provided by Agli Pançi)
No, you cannot extend a Final defined class. A Final class or method declaration prevents child class or method overriding.

Leave a Reply