PHP is the language of choice for building databases and executing special web functions inside of HTML.

Its simplicity means the language has a loyal following and, more importantly, a huge growth potential.

Whether you’re looking for a job in PHP development or are in need of a refresher before your interview for a PHP developer opening, it’s good to have the basics explained in plain English so you can do the same for your potential employers. To that end, we’ve created the following 26 fundamental PHP interview questions.

Sure, you’ve worked in PHP for a long time, so you have plenty of practice with the development language. Or maybe you’re just starting. This guide does not exist as a replacement for the many how-to PHP development guides out there.

What we’re here to do is make sure you can explain these things to an outsider, someone potentially unfamiliar with your work but who has a need for web or database development in PHP. Performing well here and getting the job in this scenario requires something more that just knowing the craft.

Instead of presenting the interviewer with a lot of technical jargon, using our guide you’ll be able to clearly explain your value in an interview.

This list has been created through the combined efforts of a writer and a professional programmer to ensure both readability and accuracy.

In case you’d like to skip ahead….

Let’s get started.

Basics of PHP

1. Define PHP

Good question! Hypertext Preprocessor—or PHP as it’s known to both you and I—is a widely-used, open source general purpose scripting language suited for web development, which can be embedded into HTML.

PHP is a versatile language that can be used to reign in a database or even create an entire e-commerce site. It can be used to deliver images, PDFs or even Flash movies to web users visiting those visiting the website you wrote it with, but the its most common use it HTML output.

Compared to a more intensive web language like C or Perl, PHP offers a relatively simple way to create digital architecture on a comparatively modest learning curve: most users can learn PHP and start coding within a few hours.

What’s more, if you’re using PHP to generate HTML, users are none the wiser as the code generates no witness marks at the end-user level, it just looks like a normal webpage to them. All the production, be that HTML or any other digital assets, is handled at the server level. In a manner of speaking, all the user gets is the dish, not the recipe for how you cooked it.

2. What are some common uses for PHP?

In general, PHP can do practically anything. It can be used across all major operating systems which include, Linux, Microsfot, Max OS X and many more. PHP is most recognised for its support across a wide variety of databases.

In most cases, PHP also supports talking to other services using protocols, text processing features as well as other additional extensions.
There are three main components where PHP scripts can be used:

  1. Server side scripting is the traditional and comment target field for PHP. In order for this to work properly, one needs a web server, a web browser and the PHP parser (CGI or server module).
  2. Command line scripting
  3. Desktop applications

More information on the documentation of PHP can be found here.

3. Why might you want to bar certain users from accessing particular areas of your PHP-made website?

Web entities are rarely one-woman shows. A server administrator is going to have to work with a team, perhaps one made up of contracted contributors whose role expires when the project is completed and may be tempted to misuse the valuable data in your PHP database.

Using the “generate-defuse-key” script, it’s possible to keep data or an entire application safe from select users, even a database administrator responsible for managing this server.

Simply put: you want the expertise, but not the risk. PHP’s ability to tailor access at the user level is a a huge strength as a coding language.

4. How do you put PHP code inside of an HTML page?

Use one of three special markup tags:

<?php THISISWHEREYOURPHPCODEGOES ?>

<? THISISWHEREYOURPHPCODEGOES ?>
<script language=”php”> THISISWHEREYOURPHPCODEGOES </script>

The most common tag is the first, but all three are recognised by the PHP Parser.

5. Is the spacing standardised on these tags and, for that matter, all PHP code?

No. PHP is what’s known as “whitespace insensitive,” which means it ignores spaces, tabs, returns or anything else that’s in the code that’s not actually code. So, to answer you original question, the spacing is not standardised here or anywhere else in PHP’s creation. 7 spaces or 77: it’s all the same to PHP, and a PHP parser is going to read it the same way regardless.

6. What about casing? Is PHP case sensitive?

Also no. PHP does not care whether your letters are big or little. A PHP parser can read them all the same.

7. What is a PHP Parser?

This is software that works to turn complex source code into something more easily and efficient digestible by a computer. Many are available, or you can write your own. Some PHP parsers like Zend PHP include an on-board editor that will check your code for errors and report them accordingly.

8. How does a PHP Parser know where to parse?

Markup tags will function as markers to define the parser’s jurisdiction in a line of code. Because a web page may contain many elements, the tags give demarcate PHP from other elements, like HTML. The tags are like instructions for where the PHP parser should begin and end working or, to borrow a phrase from the industry, “escape to PHP.”

PHP Variables

9. What are the features of a PHP variable?

First, know that all variables lead with the dollar sign, $. A variable will “remember” the value of its latest assignment, but if it’s used before the value has been ascribed it will come with preloaded default values. You can declare a variable before an assignment, but it’s not necessary.

10. How do you assign a variable to an expression?

You do that through the = operator. Put the variable on the left, and the expression in question on the right.

11. What are the different types of variables?

There are eight. They are integers, doubles, booleans, NULL, Strings, Arrays, Objects and Resources.

12. Briefly explain how the variables are used.

Integers, Doubles, Booleans and NULL variables all specify a single data point, either a number, a true/false value or a NULL value.

The others are collection of data (Strings, Arrays) or tools to call defined classes—objects made of interacting values and functions—as the Object Variable does. The Resources variable calls resources from an external resource, like another database.

13. So what is “NULL”?

This is a value that is equal to the “false,” “0” and “empty” values. A variable of data type NULL is a variable that has no value assigned to it.

If we skip data type checking, its value can be equal with “false,” “0” and “empty” values.

14. Null is false, so what is true?

Of course the “true” value is true. But PHP will also recognise a range of other true statements of the non-boolean variety. A number value is true if it has a nonzero number. A string value is true is the string is populated. If the value is an array, it’s false if it contains no other values.

15. How do you name a PHP variable?

It must begin with an underscore or a letter, but you can’t use the +, -, %, & or comma (“,”).

Constants & Errors

16. How do you create a constant?

Use the define() function and generate the value of the constant. We also can define constant with keyword “const”

17. Why would you make a constant?

Let’s say you want to retrieve a specific value, but you don’t know its name. You’re not sure if it’s stored in a variable or inside a function. You can use a constant to call up that specific value as long as it’s a boolean value, an integer or a string.

18. What are the main types of PHP errors?

There are three: a notice, a warning and a fatal error.

19. Explain what the different PHP errors are.

We’ll go by less to more severe.

A notice is a non-critical error saying something went wrong in execution, something minor like an undefined variable.

A warning is given when a more critical error like if an include() command went to retrieve a non-existent file. In both this and the error above, the script would continue.

A fatal error would terminate the code. Failure to satisfy a require() would generate this type of error, for example.

Perl vs. PHP

20. Explain how PHP variables are like Perl.

The most obvious similarity is appearance. Both PHP and Perl’s variables start with a $ in front. Both also prefer with double-quoted elements (“element”) rather than single quoted elements (‘element’). They are also functionally similar in that both Perl and PHP’s variables have no intrinsic type, meaning that you can store a number or a string in the same type of variable.

21. How are other elements of PHP similar to Perl?

Both are scripting languages rather than tools to create executables that exist before, during and after use, like a computer program.

Syntactically, both are very similar in that functions start with the name of the function followed by arguments enclosed in parentheses separated by commas. Also, Perl like PHP is “whitespace insensitive,” indifferent to spaces, tabs or any other non-language inside of the code.

22. What are the differences between Perl and PHP?

For one, PHP only has one kind of variable, which is denoted by the $. You don’t have the @ or % variables that would appear in Perl.

Functionally, the differ in that PHP requires the backing of a formal list of arguments inside C or Java, which isn’t the case in Perl.

Functions

23. What is the most immediate way to manipulate the functionality of PHP?

Why, a php.ini file of course.

Each time PHP is initialised, the php.ini file boots up. Changes there will changes the rules of the way the PHP code plays for the entire game, in a manner of speaking.

24. Explain the difference between required and include functions.

Require and include are functionally identical, except that they handle errors in a much different manner. If Include() generates an error, the function will create a warning but the script will continue execution. If require() generates an error, the script will terminate.

The simple answer is that both include a specific file but require() tells the program that the program cannot continue without getting that said file. Include() says “Hey, it would be cool if we have that, but we’ll keep going if we don’t.”

Make sense?

25. How do you connect PHP and PostgreSQL?

“That’s a really good question,” you might answer. But maybe you’re thinking “What the heck is PostgreSQL?”

Which is why you’re reviewing this guide ahead of time, worthy candidate.

PostgreSQL— make sure you pronounce it “Post-Gres-Cue-El” or just “Post-Gres”if you’re doing a live interview—is an object-relational database system that builds on the basic function of a traditional database system with enhancements available in the Database Management System (DBMS) system software.

PHP using Postgre can do prepared statements, transaction, table metadata retrieval and server variable inspection. While it seems most developers have preferred data manager MySQL API given its prevalence on the web and PHP’s native support for this tool, PostreSQL’s loyal developer following and and feature-rich environment is worth consideration by any developer worth their salt.

And, like PHP, PostreSQL is free and open source.

26. The question above seems kind of left field. Why should I prepare for this seemingly marginal-sounding question?

Glad you asked. We’ll let former Google staffer Laszlo Levente Mari answer:
One of the most important things I watch out for 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,” the IT consultant wrote.

You work with machines, but you aren’t one. Interviewers are going to want to meet curious, engaged candidates with expressed interests in growth and development. You’re answering questions with clearly right and wrong answers, but some questions—like the one above about PostreSQL’s role inside of PHP development—ask you to make a value judgement.

Why is it better? Is it better? Look for opportunities to exercise your expertise and establish yourself as the clear best hire.

If you're looking for top-quality PHP developers, don’t hesitate to get in touch with us here at Pangara. We are always ready to assist and we look forward to hearing from you.

Stay tuned in for our latest news updates and events on our Facebook page, LinkedIn and Twitter.