Table of Contents
- 1 PHP Interview Questions – Introduction
- 1.1 Question 1: What is PHP?
- 1.2 Question 2: What is a PHP ‘PEAR’?
- 1.3 Question 3: What is PHP used for?
- 1.4 Question 4: How many supported PHP versions are there?
- 1.5 Question 5: Name the types of errors in PHP.
- 1.6 Question 6: What is the most common tag to embed PHP into HTML?
- 1.7 Question 7: Is PHP an OOP programming language?
- 1.8 Question 8: When would you use ‘final method’?
- 1.9 Question 9: Is PHP multiple or single inheritance?
- 1.10 Question 10: How to enable the use of ‘image’ in PHP?
- 1.11 Question 11: How would you connect a MySQL database to PHP?
- 1.12 Question 12: How many objects can you create in PHP?
- 1.13 Question 13: Explain ‘_construct()’ and ‘_destruct()’.
- 1.14 Question 14: What’s the difference between ‘==’ and ‘===’?
- 1.15 Question 15: Can you set a maximum execution time within a PHP script?
- 1.16 Question 16: When do you use ‘@’?
- 1.17 Question 17: How do you find out the length of an array?
- 1.18 Question 18: How are objects passed in PHP – by reference or by value?
- 1.19 Question 19: Compare the ‘include()’ and ‘require()’ functions through how they deal with possible issues within the code.
- 1.20 Question 20: How to export PHP data into Excel?
- 2 General Tips
- 3 Conclusions
PHP Interview Questions – IntroductionWe’ll start off with some of the more basic PHP interview questions so that you could get a feel for what the beginning of the interview should be like. After that, we’ll transition to a bit more advanced PHP questions. All in all, at the end of this tutorial, you should have a better understanding of how the interview should go.
Question 1: What is PHP?Probably the very first question that you are likely to get asked during your job interview is “what is PHP?” or “what does PHP stand for?”. Some advice here would be that you should try to answer with as simple of an answer as you can – there’s no need to come off as fancy or a know-it-all. Your potential employers will probably appreciate that you are able to explain somewhat difficult topics in your own words. So, what does PHP stand for? Well, the acronym itself is derived from “Personal Home Page” – however, the more scientific answer would probably be “Hypertext Preprocessor”. PHP is an open source scripting language. Needless to say, it’s one of the most popular scripting languages in the world – you wouldn’t be reading this tutorial if that wasn’t the case.
Question 2: What is a PHP ‘PEAR’?The PHP PEAR is an extension of the PHP language itself. The acronym stands for “PHP Extension and Application Repository”. PEAR is mostly used by experienced programmers – it offers more options and functions than just the standard PHP version.
Question 3: What is PHP used for?There are quite a few common uses for PHP. Just to name a few:
- It can create, write, close system files.
- It can encrypt data or prevent people from accessing parts of your website.
- It’s used to play around with cookies – you modify and set them according to your needs.
Question 4: How many supported PHP versions are there?Currently, there are four versions of PHP – PHP 5.6; PHP 7; PHP 7.1 and PHP 7.2. It is generally advisable to use the newest (7.2) version.
Question 5: Name the types of errors in PHP.There are three main types of errors in PHP – notices, warnings and fatal errors. Notices are the most commonly encountered errors – they aren’t detrimental to the well-being of your code. Warnings are the tier-two errors, but they’re also non-lethal to the code running process. Fatal errors, however, are a different story – once a fatal error happens, your code running process is immediately terminated.
Question 6: What is the most common tag to embed PHP into HTML?The most common tag is:
<?php ……… ?>
Question 7: Is PHP an OOP programming language?OOP stands for “object-oriented programming”. It is a type of programming language that focuses on the object of the task, with all resources and functions aimed at creating and furthering its development. PHP 5 is considered to be a great OOP language – it possesses a lot of the features that OOP represents.
Question 8: When would you use ‘final method’?The final method is used on a method with a purpose to make it no longer overridable.
Question 9: Is PHP multiple or single inheritance?This is one of the more fancy-worded PHP interview questions, but don’t let it fool you – the answer is actually pretty simple. In PHP, you can only extend a class form another singular class – this means that PHP is of single inheritance.
Question 10: How to enable the use of ‘image’ in PHP?
Question 11: How would you connect a MySQL database to PHP?You would do so following the code below:
connection mysql_connect(pepper, Daniel, 12345, Applesauce, client_flag);Here, “pepper” is the host while “Daniel” is the username and the numbers 1-5 are an example of a password. “Applesauce” is the name of the database that you’re trying to connect to.
Question 12: How many objects can you create in PHP?Unlimited. However, there’s a catch.
$car = new Tires();
Question 13: Explain ‘_construct()’ and ‘_destruct()’.In PHP, objects belonging to classes have inbuilt Construct and Destruct options. Once you create a new object within a class, the
constructoption is automatically enabled within it. This allows the object to copy the parameters and settings of the class and automatically assign them to itself. On the other hand, if
destructis enabled, it automatically deletes any and all settings of the new object.
Question 14: What’s the difference between ‘==’ and ‘===’?
==(equal) should be used when you want to check if the values of two separate operands are equal to each other or not.
===(identical), on the other hand, should be used when you want a super specific answer – it checks not only the values but also the types of operands.
Question 15: Can you set a maximum execution time within a PHP script?Yes, yes you can, and there are actually two ways to do it. But why would you want to do that in the first place? Sometimes, when you run your code, you might encounter an error that warns you that you exceeded the ‘maximum execution time’ limit. This will prevent your code from running further on, thus failing the process. To avoid this, you need to implement a command
set_time_limit(0)in the very beginning of your code. Another way to do this is to implement the same command in the .ini file.
Question 16: When do you use ‘@’?The “@” command is used to avoid problems in your code by simply telling PHP to deal with them for you. What you would do is simply add the “@” command at the beginning of a line with code that might provoke an error message. Once added, “@” will pass any and all errors that line of code provokes to PHP.
Question 17: How do you find out the length of an array?To find out the length of an array, you would simply need to utilize this code:
<?phpThe output here is 4. The sentence “PHP is really cool” is made out of 4 words, which is equal to the output. This means that the code worked!
$array=['php', 'is', 'really', 'cool'];
Question 18: How are objects passed in PHP – by reference or by value?This is yet another one of those PHP interview questions and answers that are closely related to OOP – in PHP, objects can only be passed by value.
Question 19: Compare the ‘include()’ and ‘require()’ functions through how they deal with possible issues within the code.The
include()command isn’t of the highest priority, so if a code execution fails at the point where
include()is located, it will only send out a warning and continue running. As for
require(), it is quite a different story. As the name of the function implies, that portion of the code is required to be able to load the program. If there’s an error where
require()is located, the code will experience a fatal error and crash.