PHP Interview Questions | Top 50 PHP Interview Questions

Top 50 PHP Interview Questions

Last Updated by Monika Dadool 10-Feb-20

1 8542

Hey all,

Being from an IT background myself, I have always been keen to learn about PHP development. I know you do too, that is why you are probably reading my blog!

So, collected from my personal experience of attending an ample number of PHP interviews, I have devised a list of PHP Interview Questions including almost every question I have faced while my interview session.

Top 50 PHP Interview Questions

I will also help you with properly framed answers to each question to improve the way you are preparing for your interview.

Advanced PHP Interview Questions Answers List

1. What do the initials of PHP Stand for?

PHP means PHP: Hypertext PreProcessor that previously stood for personal home pages.

2. Who is the father of PHP?

Rasmus Lerdorf

3. The basic question that can come under both simple to advanced PHP interview questions is "what do you mean by PHP"?

PHP is an open-source server-side scripting language that allows creating web pages dynamically and is used for web applications and can be embedded into HTML code.

To access PHP Scripts, only a web browser is required by the client computer. PHP can also be used in combination with various web content management systems, web template systems, and web frameworks.

4. Which programming language does PHP resemble?

PHP syntax bears resemblance with PERL and C.

5. What PHP version is extensively used currently?

Version 7.1 / 7.2

6. What do you mean you say PHP is Open-Source?

Open-Source Software refers to the software that is dispersed with source code, can be freely used, read, modified and shared by anyone.

PHP is an Open-Source Software (OSS) as it meets the following benchmarks:

a) The source code of PHP is included with the program and is distributed freely.

b) Modified versions of source code for PHP are also redistributed.

c) Users are able to modify the distributed PHP source code.

7. How can we submit a form without a submit button?

JavaScript submit() function can be used to submit the form without the submit button on click call document.formname.submit ().

8. How can we create a database using PHP and MySQL?

We require a database before saving or accessing any data and to create any database in MySQL, CREATE DATABASE Statement is used.

e.g. mysql_create_db("Database Name")

read more

9. How to include a file to a PHP page?

It is possible to include one PHP file's content to other PHP files. The two functions "include()" and "require()" with file path as its parameter can be used to include a file.

10. What is the role of Ksort() in PHP?

Ksort() is an inbuilt PHP function which is used to sort an associative array key in ascending order of its key values. For example:

$age=array("Jai"=>"59", "Dolly"=>"43", "Mack"=>"49", "Sam"=>"46");

foreach ($age as $a => $b)
echo "$a = $b\n";


Dolly = 43   Jai = 59   Mack = 49   Sam = 46

11. How to get the value of current session id?

session_id() function can be used to return the session id.

12. What are the functions of the header() function in PHP?

This function is used for sending a raw HTTP header to the client, and redirection of pages. It is very important to remark, that header() must be called before the real output is seen, either by blank lines in a file or from PHP or HTML tags.

13. Are multiple inheritances supported in PHP?

PHP includes only single inheritance. A Class can be extended from only one class and the keyword used is 'extended'.

14. How can we execute a PHP script using command line?

We just need to run the PHP command line interface program and add the PHP Script file as the Command line argument

echo "Test";
echo "\n";

The following are the four steps and paths that can be used to execute PHP in the command line.

  • First login to your windows system.
  • Press windows and R key of the keyboard simultaneously to open a command prompt.
  • To find PHP executable file, move across the PHP directory.
  • The executable file is accessed and then Path to PHP File.

The path with the Change directory command used is C:\wamp\bin\php\php5.3.13. For Wamp Webserver users: php.exe path-to-your-php-file. If you visualize PHP version info, you can use PHP path-to-your-php-file instead of that command.

15. How can PHP and HTML interact?

It is possible to generate HTML through PHP scripts and it is possible to pass information's from HTML to PHP.

16. What are the final methods and a final class?

The Final is introduced in PHP5. Final methods cannot be over-ride and the final class cannot be extended.

17. What is the difference between PHP4 and PHP5?

  • Zend Engine II is used while Zend engine 1 was is used in PHP4.
  • The addslashes() function is used in PHP5 instead of Magic quotes used in PHP4.
  • The more procedure ordinate language in PHP4 is replaced with additional object-oriented concepts in PHP5.
  • Abstract classes can be declared in PHP5 which was not possible in PHP4.
  • Static methods and properties and exceptions are introduced in PHP5 which were not present in PHP4.
  • There is three levels of visibility are present in PHP5 i.e. public protected and private.

In PHP4, all objects were passed by value but in PHP5, all objects are passed by reference and more reserved keywords are used in PHP5

18. How can we directly display output to the browser?

Special tags <? = and?> are used to display directly to browser.

19. How comparisons of objects are done in PHP5?

The operator '==' is used to test whether two objects are instanced from the same class, having equal values and the same attributes. We can test if two objects are referring to the same instance of the same class by the use of the identity operator '==='.

20. What type of operations is needed when values are passes through a URL or a form?

We require them to encode and decode with two functions htmlspecialchars() and urlencode.

21. How the result sets of MySQL is handled in PHP?

These can be handled with the use of mysql_fetch_assoc, mysql_fetch_array, mysql_fetch_row or mysql_fetch_object.

22. What is the function mysql_pconnect() used for?

mysql_pconnect() assures a continual connection to the database. It means that even PHP script ends, the connection does not close.

23. Explain the different errors that occur in PHP?

There are mainly four types of error found in PHP:

  • Fatal Error
  • Warning Error
  • Parse Error
  • Notice error

Fatal Error: Fatal errors are known as critical runtime errors that occur when we try to access inaccessible data. When this error occurs; it results in immediate script termination.

e.g. trying to access the undeclared function and dead objects.

Parse Error: These types of errors are found when there are syntax faults in code. When this error occurs, it stops scripts execution.

E.g. if there are mismatch brackets or semicolon missing.

Warning Error: These errors will not stop script execution but give the warning and continue with a further line of the script. Warning errors occur when we try to include the missing files or when we try to use the wrong number of parameters in a function.

Notice Error: These errors resemble warning errors i.e. execution does not halt script. It also gives the notice and continues with a further line of the script.

24. What is the difference between PHP and JavaScript?

PHP is a server-side scripting language whereas JavaScript is a client-side scripting language.

25. What is the difference between $$name and $name?

$$name is a reference variable whereas $name is variable.

E.g. $name=kelvi and $$name=joy so $kelvi value is joy

26. What is PEAR in PHP?

PEAR stands for PHP extension and application repository which is a framework consisting of collections of PHP reusable components, libraries and codes snippets. It is used to ease the life of the developer and make it more comfortable and secure.

PEAR also provides a command-line interface to automatically install packages.

27. What is the name of the scripting engine in PHP?

Zend Engine2

28. What are the various methods used in the form of submission of PHP?

Two methods i.e. get and post

29. How can we get the browser properties using PHP?

We can use the following simple code to get the browser properties:

echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$browser = get_browser();

30. What is a session in PHP?

A session is an alternate way to make stored information accessible across the multiplied pages. The function used to create a session is session_start(). A file is created in a temporary directory by a session on the server, which consists of variables and their values. This information will be made available to various pages on the site.

When we create any working environment, we open an application and do some modifications and after that terminate that application. This is more similar to the session.

Our computer knows all the logging information about us but when we are accessing the internet, there one problem occurs: the web server does not have information. This problem is solved by session variables. The session helps to make customized web application where user tracking is required.

31. How we can destroy any session?

We can use the destroy function described in the following syntax.


32. What is the difference between unset and unlink function?

When we want to destroy any variable, we can use the unset() function and when we want to destroy a file, unlink() function is used.

33. How we can get the current session ID?

For this, we have to go to session start and then go to echo session id

echo session_id();

34. How we can differentiate between explode and split functions?

Both explode and split functions are used to split a string in an array and the common difference is that while explode uses a string and split uses a pattern.

Explode is faster than split because it does not perform regular expression based matching, so regex parser is not required to analyze the string. Split() has been deprecated as of PHP5.3.0 and the use of this split function is pessimistic.

35. What is the use of PDO classes?

PDO stands for PHP Data Object. PDO contains collections of PHP extensions that provide database precise drivers and core PDO classes. It also targets data access abstraction.

To be compatible with the latest versions of PHP, the advanced OOPS feature is required. It grants a lightweight data-access abstraction layer persistent interface to access databases in PHP.

36. What is the use of count() function in PHP?

It is used to count the properties and elements of an object recursively

count(array_name, mode)

Where array name specifies countable object and mode sets the function's mode.

37. During PHP installations which function creates an HTML page to display records of how PHP was installed?


38. What is the difference between print and echo in PHP?

Both print and echo are used to display output data on a screen and there are very minor differences are described below:

Print can be used in expressions and has a return value of 1 whereas echo has no return value. Print can take only one parameter whereas echo can take multiple. The print is slower than the echo.

39. What is the difference between session and cookie?

Session is more secureCookie is less secure because cookie's values can be easily accessed
Session is stored on the server side Cookie is secured on the client's computer
Session can hold multiple variablesMultiple variables are not held in cookies
We can store unlimited dataWe can store data in limits
The session_start() function must be used before the HTML tagThe setcookie() function must be used before the HTML tag

40. What is the purpose of php.ini file?

When we install and explore PHP, we will find one configuration file where we can visualize, access, and modify the functionality of PHP. This file is the current and final way to affect the functionality of PHP in which we can declare changes to PHP settings by editing the existing php.ini file. The php.ini file is read each time PHP is initialized.

We can create a new php.ini file in cPanel in the following steps:

  • First we have to log in to the cPanel.
  • Click on the File Manager icon in the Files category.
  • Click Go after selecting the Home Directory.
  • On top of the page, click the new file button and enter php.ini in the new file name field.
  • Click the file named php.ini.
  • Select and click the edit button.

41. What is escaping to PHP?

To differentiate PHP code from other elements, the PHP parsing engine is required. This mechanism is known as escaping to PHP

42. Is it possible to create a class in PHP?


43. How will you retrieve source line with the use of exception class in PHP after an error has occurred?

Getline method() can be used to return the source line.

44. PHP is a case sensitive language?

Yes, PHP is a case sensitive except user-defined functions

45. What is the objective of getdate() function?

To return the current time or date information or timestamp, the getdate() function is used.

The syntax used is getdate(timestamp);

Where timestamp is optional and specifies an integer Unix timestamp.

46. Explain PHP variables.

Variables can be used to store data like numbers, a string of text, etc. Once a variable is declared, it can be reused all over the code and the assignment operator is used to assign the value to the variables.

$var_name = value;
Variable names used in PHP are case sensitive.

read more

47. How to redirect a page in PHP?


48. What is the difference between POST and GET methods in PHP?

The browser client can send information to the webserver in two ways i.e. the GET method and POST method.

POST MethodGET Method
This method can transfer a large amount of data.Get method can send a limited amount of date i.e.1024 bytes.
More Secure.Less Secure.
POST is used for writing data.GET is used for retrieving data.
Data is not visible to the user.Data is visible to the user.
We can make a bookmark by using POST.We cannot make a bookmark.
In POST, all data control travel through URL.All data travel through the URL as well.

49. Name PHP supported database?

There are many PHP supported databases available for e.g.

  • MySQL
  • SyBase
  • MongoDB
  • Oracle
  • SQL server

50. What the difference is between include and require in PHP?

If we include a file that does not exist, it will simply throw an error and the rest of the script will run.If user require and that file does not exist then it will throw an error and halt the script from further execution
Syntax: include(file_name);Syntax: require(file_name);
If the file is not important to include then we should use include so that script should continue even when the file is not foundIf the file is important then we should use require so that it should stop to execute when the file is not found

These are the list of top 50 PHP interview questions extracted from important concepts of PHP.

Students are recommended to go through these questions for revision and to learn PHP online along with examples; we have prepared PHP tutorials for the beginners.


Leave a Reply

  1. Sanket Jan 21, 2019

    Good mam so usefull