PHP developer interview questions

2 min read
Even if the interviewer doesn't know the answers to these questions, they could probably get a
good idea for a job candidate's comfort with the material from how much they stutter and squirm
after each question.
1. What are the current versions of Apache, PHP, and MySQL?
2. What is a cookie and how is it useful?
3. If you run into a problem while coding, what steps do you take to find the answer?
4. What files are commonly found in these standard UNIX directories?
1. When you want to show some part of a text displayed on an HTML page in red font
color, what different possibilities are there to do this? What are the advantages and
disadvantages of these methods?
2. What's the difference between and
1. What is the primary advantage of CSS?
2. Describe the different ways to have content initially hidden on a page?
3. Explain the purpose and implementation of a float?
4. Describe the inherent CSS differences between IE and Mozilla.
1. How can we submit a form without a submit button?
2. Do you use DHTML and Javascript? Describe the projects you've used them in.
3. Describe some methods to redirect a page in Javascript and PHP.
1. What is the difference between $message and $$message?
2. What are the differences between PHP3, PHP4, and PHP5?
3. How can I execute a PHP script using the command line?
4. How can we increase the execution time of a PHP script?
5. What are public, private, protected, and static methods?
6. What is an abstract class and interface?
7. What is meant by urlencode and urldecode?
8. How do you set a session variable?
9. How do you set a cookie? How about reading the value within the same page execution?
10. What are two different ways of unsetting a cookie on the user's machine?
11. How do you encrypt data using PHP?
12. What is the difference between an enumerated array and an associative/hashed array?
13. What are the differences between require, include, and include_once?
14. How do you increase the allowable execution time of any PHP script?
15. What will this output?
$a = false;
$b = true;
$c = false;
if ($a ? $b : $c) {
echo 'false';
} else {
echo 'true';
16. What will this output?
$txt_var1 = "PHP";
$txt_var2 = &$txt_str1;
$txt_var2 = "MySQL";
echo $txt_var1 . $txt_var2;
17. What does this do?
if (isset($_REQUEST))
while(list($varname, $varvalue) = each($_REQUEST)) { $$varname =
$variable; }
1. How can we repair a MySQL table?
2. A select query over a large table runs very slow because of the growing number of entries
in a table. What different measures could be taken to improve speed?
3. What are different types of tables in MySQL and their differences?
4. What is the difference between GROUP BY and ORDER BY in SQL?
5. How do you encrypt data present in a MySQL table using MySQL?
6. What is an EXPLAIN? What does its result look like?
7. What is an alias? What elements can be aliased and how would one do so?
8. What are 3 different methods of adding data to a table?
9. What is the difference between "DELETE FROM [...]" and "TRUNCATE TABLE [...]"?
Elaborate on the following acronyms:

Admittedly, I stole this question from somewhere else (can't remember where I read it any more)
but thought it was funny:
A: It’s the scope resolution operator (double colon)
An experienced PHP'er immediately knows what it means. Less experienced (and not Hebrew)
developers may want to read this.
But more serious questions now:

Q: What is the cause of this warning: 'Warning: Cannot modify header information - headers
already sent', and what is a good practice to prevent it?
A: *Cause:* body data was sent, causing headers to be sent too.
Prevention: Be sure to execute header specific code first before you output anybody data. Be
sure you haven't accidentally sent out whitespace or any other characters.

Q: What is wrong with this query: "SELECT * FROM table WHERE id = $_POST[ 'id' ]"?
A: 1. it is vulnerable to SQL injection. Never use user input directly in queries. Sanitize it first.
Preferably use prepared statements (PDO) 2. Don't select all columns (*), but specify every
single column. This is predominantly meant to prevent queries hogging up memory when for
instance a BLOB column is added at some point in the future.

Q: What is wrong with this if statement: if( !strpos( $haystack, $needle ) ...?
A: strpos returns the index position of where it first found the $needle, which could be 0. Since
0 also resolves to false the solution is to use strict comparison: if( false !== strpos(
$haystack, $needle )...

Q: What is the preferred way to write this if statement, and why?
if( 5 == $someVar ) or if( $someVar == 5 )
A: The former, as it prevents accidental assignment of 5 to $someVar when you forget to use 2
equalsigns ($someVar = 5), and will cause an error, the latter won't.

Q: Given this code:
function doSomething( &$arg )
$return = $arg;
$arg += 1;
return $return;

$a = 3;
$b = doSomething( $a );
...what is the value of $a and $b after the function call and why?
A: $a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the
return value of the function is a copy of (not a reference to) the initial value of the argument.

OOP specific
Q: What is the difference between public, protected and private in a class definition?
A: public makes a class member available to "everyone", protected makes the class member
available to only itself and derived classes, private makes the class member only available to
the class itself.

Q: What is wrong with this code?
class SomeClass
protected $_someMember;

public function __construct()
$this->_someMember = 1;

public static function getSomethingStatic()
return $this->_someMember * 5; // here's the catch
A: Static methods don't have access to $this, because static methods can be executed without
instantiating a class.

Q: What is the difference between an interface and an abstract class?
A: An interface defines a contract between an implementing class is and an object that calls the
interface. An abstract class pre-defines certain behavior for classes that will extend it. To a
certain degree this can also be considered a contract, since it guarantees certain methods to exist.

Q: What is wrong with classes that predominantly define getters and setters that map straight to
its internal members, without actually having methods that execute behavior?
A: This might be a code smell since the object acts as an ennobled array, without much other

Q: Why is PHP's implementation of the use of interfaces sub-optimal?
A: PHP doesn't allow you to define the expected return type of the method's, which essentially
renders interfaces pretty useless. :-P
PHP Web Developer Interview Questions
We’ve organized the questions into several categories to help you prepare for the interview.
General Web Industry Questions
These questions are used to measure the candidate’s understanding of the web in general and
give you an idea of how they keep up to date on industry trends.
1. What do you do offline to learn about your work online?
2. What industry blogs do you enjoy reading?
3. Do you prefer working on a team or alone?
4. How would you rate your level of expertise in a shell environment?
5. Can you show me some of the code you have written in the past?
6. What is your favorite programming language? Why?
7. What web browser do you use?
8. Do you have your own personal site? What is it? What’s the purpose of your site?
9. Have you ever worked on an open source project? Was your code accepted into the project?
10. What’s the largest website you’ve worked on? What specifically did you code on that site?
11. How did you get into PHP?
12. What is a cookie and what do you use it for?
13. How does a cookie differ from a session variable?
14. If you run into a problem while coding, how do you find a solution?
15. What is XML? When do you use it?
16. What is LAMP?
17. Is PHP an old language? Should we be using .NET instead? Why? Why not?
18. What is HipHop for PHP?
19. What is the largest site on the Internet running on PHP?
20. Outside of PHP, what web development areas do you believe you are most strong in?
21. How do you connect to a remote Linux server?
22. If your Apache web server is serving pages slowly, how would you troubleshoot the problem?
PHP Technical Questions
The bulk of your interview will be focused on these questions. These are the in-depth technical
PHP questions you will use to identify the right candidate. Even if you are not proficient in PHP
itself, you will learn a lot based on how well a candidate answers these questions.
23. Have you ever used a PHP framework? What’s your favorite? What are the major differences
between the major PHP frameworks?
24. You’re receiving an error when uploading a file that the limit is set too low. Where would you
change the setting to allow for larger file uploads?
25. (Give the candidate some broken source code) Fix this code please.
26. What features would you add to PHP if you could?
27. What the different is between include and require?
28. How and when would you use endif to end a conditional statement?
29. Under what circumstances would you use === in a conditional statement?
30. Explain what the ternary conditional operator is.
31. What is an array?
32. How would you combine two variables together into a new variable?
33. When would you use Get versus Post? What are the major differences between the two?
34. How would you access information sent via Post? Get?
35. How do you encrypt data using PHP?
36. Describe your experiences with web services.
37. If I told you I needed data from a web service, would you prefer it in XML or JSON?
38. In general terms, describe how you would extract data from a web service if it returns JSON?
39. What is a regular expression? How do you use regular expressions in PHP development?
40. How many times can you include a php file in another php file?
41. How do you send email in PHP?
42. How do you increase the maximum script execution time for PHP?
43. How would you sort an array in PHP?
44. What do we uses classes for in PHP? In what cases would you define a class?
45. What’s the difference between echo and printf?
46. How do you calculate the number of days between two dates in PHP?
47. When I open up a web site you developed and it’s a blank white screen, what steps do you take
to troubleshoot the problem?
48. How would you redirect a page in PHP?
49. What is ob_start(); used for? Why would you use it when developing web pages?
50. How do you define a constant in PHP?
51. How do you determine if a constant is defined in PHP?
52. What is the difference between <? ?> and <?php ?>?
HTML/CSS Questions
Though your candidate may only do PHP development, he/she still needs to understand HTML
and CSS well enough to produce a good looking product.
53. Are you comfortable coding HTML by hand?
54. Can you write table-less code using CSS?
55. If you are presenting an error message and want the text colored red, how would you achieve
56. How would you hide content on a page? How would you show hidden content later?
57. What does float left do? How would you clear a float?
58. What browser is the most difficult to write good, clean code for? What are the major problems
with this browser?
59. What is an inline style? When would you use it?
60. What width should you develop a web page for?
61. What tools do you use to ensure your code passes w3c compliance?
62. When you create an element, how do you create a name for it so you can target it using CSS or
JavaScript Questions
Many systems use a form of Ajax to make them work right and JavaScript is essential to any
Ajax. These questions will test the JavaScript knowledge of your candidate.
63. Is JavaScript a programming language? Why/why not?
64. Do you have experience with JavaScript frameworks? Which ones? Which one do you like the
most? Why?
65. How do you submit a form without user interaction?
66. What is Ajax?
67. Describe code you have written which uses Ajax. Why did you use Ajax? How did you implement
it? Why did you write it with Ajax in mind?
68. What is jQuery?
69. How would you animate an object on the page?
70. What is the DOM?
71. What are two ways you could attach JavaScript to an element to be executed on click?
72. When would you write JavaScript on a web page and when would you include it in an external
MySQL Questions
Most PHP systems which require a database rely on MySQL. These questions are focused on
MySQL and databases.
73. How would you fix a corrupt table in a database?
74. What is a primary key?
75. What is an inner join? Left join? Right join? How are they different?
76. Write a simple query for me to query all of the columns in a particular table.
77. You have two tables which are connected via a unique ID. Write a query which will query both
tables based on that unique ID.
78. You have a table with an unknown number of records. You want to delete half of the records.
You don’t care which records are deleted. What’s the most efficient way to do it?
79. How would you create a new table in MySQL?
80. What is a stored procedure? When would you use a stored procedure? Have you ever written a
stored procedure?
81. What is the difference between GROUP BY and ORDER BY?
82. What is UNIQUE used for?
83. What is DISTINCT used for?
84. What is a temporary table?
85. How would you select data into a temporary table?
86. How do you delete records in MySQL?
87. What is an alias? What would you use it for?
88. How do you encrypt data in MySQL?
89. What is a table index? Why would you use it?