20 Common PHP Job Interview Questions and Answers

Taylor Hawkes

Author: - at the lake.

I've been interviewed by many companies for PHP development positions, every company has a slightly different interview process, but there seems to be a lot of commonalities among them. I've outlined below the main areas that companies look for knowledge in, and some questions/answers you may get asked. At the end of the day you will not be able to entirely fake your way through a good interview, but I thought this would be a huge help for newer or mid level developers going into an interview. If you are totally new to PHP or programming www.teamtreehouse.com is a great place to start. Don't forget to me on Twitter so you can stay up to date with whats going on in the PHP world.

  1. What is Object Oriented Programming?
  2. likelihood high
    This is usually a pretty open ended question. You should understand classes (objects are instantiated classes), abstract classes, interfaces, methods, properties,inheritance, multiple inheritance as well as why OOP is helpful as compared to procedural programming.
  3. In PHP what is the difference between a Class and an Interface?
  4. likelihood high
    Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decide not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.
  5. What is MVC?
  6. likelihood high
    Most programmers know this, but interviewers will likely look for a deep understanding of MVC, and some explanation or examples on how/why/ when you used it.

    MVC- Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own job.

    Model - Usually contains data access code and all of you business logic code.
    View - Contains markup/design code, generally html,xml, json.
    Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.
  7. Explain how a PHP session works?
  8. likelihood high
    A PHP session cookie is set in the clients browser, on every request the client sends that cookie to the server. PHP then uses that cookie to select the corresponding session information. By default PHP session_start() will store session data in files, you can also store sessions in a database.
  9. What are some of the big changes PHP has gone through in the past few years?
  10. likelihood high
    There are a number, but the big ones people are looking for are:
    a. PHP 5.0 realised the object model (AKA OOP).
    b. 5.1 added PDO - for accessing databases.
    c. 5.3 - added namespace support and late static bindings.
  11. What is the difference between $_GET and $_POST
  12. likelihood high
    This is a great question because an interviewer can tell how deeply you understand HTTP and the request/response. If you don't have good understanding of HTTP protocol, google around and get a grasp on it.
    Good answer
    Explain the HTTP protocol and how every request contains a method, generally(GET,POST,PUT,DELETE) and what each method signifies.
    Bad answer
    $_GET stores variables passed in url as query strings. $_POST stores variables past from using method = $_POST
  13. In a PHP class what are the three visibility keywords of a property or method?
  14. likelihood medium
    public, private and protected. The default is public.
    Public -> Any class may instantiate the class and call the method or property.
    Protected -> Only the class itself or inherited (children) classes may call a method or property.
    Private -> Only the class itself may call a method or property.
  15. What is Polymorphism?
  16. likelihood medium
    Don't get scared by the big word. It's simply the idea that one object can can take on many forms. So in PHP OOP one class "cars" may have two classes that extend it, for example a "Honda" class and a "BMW" class.
  17. How do you load classes in PHP?
  18. likelihood medium
    They are trying to gauge your understanding of how class auto loading works. Review the "autoload" and "spl_autoload_register" function (note:you should use the later). The autoload function basically triggers a function when a class is instantiated, you can put whatever logic you like in it but generally you want to include the class file based on some sort of naming convention.
  19. What is the value of "$day" in the below code?
  20. likelihood medium
    $wed= 1;    
    $day = ($wed==1) ? 'today' : 'tommorrow';
    // $day is now set to 'today'
    Companies often ask about the ternary operator (?). which is simply a shorthand for if else statements.
  21. What is the Scope Resolution Operator?
  22. likelihood medium
    "::" double colons is the scope operator it is used to call methods of a class that has not been instantiated. You should also understand static methods and how they differ from regular methods.
  23. What are some PHP Design patterns you have worked with?
  24. likelihood medium
    Design patterns are simply commonly used techniques within your code, they often are implemented in different ways so they can be a bit tricky to grasp without writing them yourself. If you are unfamiliar with them I would start by learning the Singleton Pattern and the Strategy Pattern.
  25. What is the difference between single quotes and double quotes?
  26. likelihood medium
    Great answer at below link.
  27. What does ob_start do?
  28. likelihood medium
    Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.
  29. What does "&" mean in '&$var' ?
  30. likelihood medium
    '&' indicates a reference
  31. What is the meaning of a final class and a final method?
  32. likelihood medium
    Final keywords indicates that the class or method cannot be extended.
  33. Does PHP support multiple inheritance?
  34. likelihood medium
    No. You should understand what multiple inheritance is.
  35. What are some magic methods in PHP, how might you use them?
  36. likelihood medium
    Magic methods are basically triggers that occur when particular events happen in your coding. __GET, __SET are magic methods that are called (behind the seen) when you get or set a class property.
  37. Are objects in PHP 5 passed by value or reference?
  38. likelihood medium
    This is basically a trick questions. To understand how they are passed you need to understand how objects are instantiated. Study the below link:
  39. What is the difference between $var and $$var?
  40. likelihood medium
    $$var sets the value of $var as a variable.
                $$day='first day of week';
                echo $monday; //outputs 'first day of week'

Comments (101)

You're reviewing: Common php questions
Newest | Oldest   Helpful   Positive | Critical
Full StarFull StarFull StarFull StarHalf Star 4.5/5 (74)
Full StarFull StarFull StarFull StarEmpty Star
Rizo says...
Great effort ... Ist very helpfull for me ...
23rd January 2015 4:54am
Full StarFull StarFull StarFull StarEmpty Star
rishu khanna says...
fast job
good service
6th January 2015 7:50am
Full StarFull StarFull StarFull StarFull Star
Supun says...
thanks,its help me a lot
18th December 2014 1:38am
Full StarFull StarFull StarFull StarFull Star
Taleeb says...
Great effort! Thanks a lot
3rd December 2014 1:47pm
Full StarFull StarFull StarFull StarEmpty Star
anilmcmt says...
nice question
23rd November 2014 9:12am
Full StarFull StarFull StarEmpty StarEmpty Star
Johan says...
The chocolate flaking were quite a nice tip to add. I remember cooking egg once and added in my burger.
17th November 2014 9:15pm
Full StarFull StarFull StarEmpty StarEmpty Star
dawood shah says...
Hello, i believe that i saw you visited my weblog thus i came to
go back the favor?.I am attempting to in finding issues to improve my site!I assume its good enough to make use of some of your
19th August 2014 4:27pm
muthu says...
thank u sir
15th August 2014 6:39am
Antoinette says...
In an internet forum about plastic surgery, it will be possible to come in contact with other individuals about plastic surgery through the net.
And a proficient plastic surgeon with a lot of experience,
can take that even further. With an type of plastic surgery, there will be a
recovery process.
19th July 2014 12:18pm
Hamish says...
I used to be recommended this blog by my cousin. I'm no longer certain whether or not this put up
is written by way of him as nobody else recognize such specified about my difficulty.
You are wonderful! Thank you!
17th July 2014 11:17am
Oren says...
One function of the bustle and the hoopskirt was to make the waist look smaller and to enhance the bust.
So, all of them will buy a pair of beautiful chinese embroidered
shoes without any hesitant. Healthy clear beautiful skin is a must for models because bad skin does
not photograph well.
16th July 2014 11:07pm
Jacklyn says...
Replacing the wax ring is a lot less difficult and
expensive than replacing the toilet, but if you have wanted a new commode, this is your chance.
Flat paint is the best choice for hiding rough spots and
surface imperfections, which makes it perfect for ceilings and walls.
The body definitely contained a high volume of mucous and yeast.
15th July 2014 8:49pm
Dorie says...
Make sure you know how long it requires to recover from a
plastic surgery process ahead of agreeing
to it. In 2009, men undergoing some sort of cosmetic surgery procedure rose
eight percent. The various types of plastic surgery on the face are:.
15th July 2014 8:11am
Jarred says...
Here's a review of the various sunless product lines for your guidance.

The destruction of the prewar establishments left everyone
starting and rebuilding from scratch, and those who had a wider
perception of the people's needs seemed to
had the greater advantage. The rise in popularity of sunless tanning products
as a part of the indoor tanning industryyes tanning has indeed spurred the creation of
a whole new industry decades agohas led psychologists
and sociologists to speculate on this apparent need
of Americans to be tan.

14th July 2014 2:08am
Katia says...
Excellent beat ! I would like to apprentice while you amend your web site, how
can i subscribe for a blog site? The account helped me a acceptable deal.
I had been tiny bit acquainted of this your broadcast provided bright clear idea
8th July 2014 12:46pm
Milagros says...
If or when your favorite game in your youth was creating clothes for
your toys as well as creating creative changes in your very own apparel, then I think people such as
you are absolutely those which are destined to become a
fashion designer. This fabric is intended to be loose fitting,
but wear it too loose and you'll look fat. You will
be excited watching your kids in pastel tones especially when summer comes.
4th July 2014 10:30pm
Kelley says...
Enjoy these finger foods with beverage...for a
great way to start your day. Sometimes, we feel desperate when our
exercise habits seem too long to take effect. Before
cooking, you should remove all the fat on the meat. When we are overweight or obese,
we don't think positive thoughts about ourselves and we spend a
great deal of time beating ourselves up for being weak when it comes to food.
This plan is projected to put the body into starvation mode.
"Knowing the odds of successful outcome using chemotherapy are nil in many cancer cases, why do you continue to prescribe chemotherapy. - High protein items are always an excellent type of dieting food. The company has a good guarantee of its all products and diet plans. They claim to not have hunger issues or other problems. On the average diet the first 10lbs of weight comes off quite effortlessly.
4th July 2014 10:13pm
Anthony says...
I don't even know the way I ended up right here, but I thought this put up was good.
I don't recognize who you might be but certainly you are going to a well-known blogger if you aren't
already. Cheers!
14th June 2014 7:01pm
Antje says...
It's amazing in favor of me to have a site, which is helpful
designed for my knowledge. thanks admin
8th June 2014 2:54am
Hildegarde says...
What's up to every one, the contents present at this site
are in fact awesome for people experience,
well, keep up the nice work fellows.
5th June 2014 8:24am
Page 3 of 6

Add Comment

* Required information
(will not be published)
Powered by Commentics
Copyright 2008 Woodstitch all rights reserved