Core PHP Interview Questions

By | October 21, 2021
PHP Interview Questions

The more popular the PHP is the more opportunities to work with it. The features this language supports make it unique from others. PHP is a scripting language that is easy to learn and simple to use for all levels of programmers. PHP supports a large community that is ready to help you whenever you have any doubt related to PHP code. PHP also supports cross-platform that allows it to use anywhere and this is also an important reason for its popularity. So let’s discuss the Best PHP Interview Questions.

There are so many big companies in the IT industry that are using PHP for their platforms, so you may have an idea that what’s the scope of your career in PHP for the future. But before joining any company, you must have to face the interview round and there interviewer will check your conceptual knowledge about PHP or more if you are not fresher. For that, you must be well prepared for the Interview. To help you in that, here we have prepared a list of the most frequently asked interview questions for PHP. Have a look at it before your interview.


Best PHP Interview Questions and Answers

Here we have listed the best PHP interview questions and answers though you can prepare for the back-end interviews

1. What is PHP?

Answer: PHP is a Hypertext Preprocessor is a general-purpose, open-source, scripting language that runs on the server-side that is mainly designed to use for web development. PHP scripts execute on the server. PHP scripts are dynamically typed and generate web pages efficiently and quickly. PHP is freely available to download and use. Its syntax is mostly borrowed from object-oriented programming such as Java and Perl.

2. What is the full form of PHP?

Answer: Hypertext Preprocessor

3. What does PEAR stand for?

Answer: “PHP Extension and Application Repository”. PEAR extends PHP to provide a higher level of programming for web developers. PEAR also offers a CLI (Command Line Interface) that can be used to automatically install “packages”.

4. Which programming language does PHP resemble?

Answer: PHP syntax derived from Perl and C.

5. What are the differences between PHP & JAVA?


PHP Java
Server Side Scripting Language High-Level General Purpose Programming
Dynamically Typed Statically Typed
It doesn’t have a rich set of APIs It supports a rich set of APIs

6. What is the latest version of PHP?

Answer: The latest version of PHP is PHP 8.0.11 released on 23 September 2021.

7. Which version of PHP is mostly used?

Answer: Version 7.1 or 7.2 is the recommended version of PHP which is mostly used.

8. What is the command to execute a PHP script from the command line?

Answer: Use the PHP command-line interface (CLI) and write the exact file name with .php extension to be executed as follows:

php script.php

9. Which function is used to encrypt the password in PHP?

Answer: To create one-way encryption, crypt () function is used in PHP. This function is defined as crypt (input_string, salt), where input_string is defined as the string that has to be encrypted and salt represents an optional parameter. DES is used for encryption in PHP. The format is as follows:

$password = crypt('intellipaat');
print $password . "is the encrypted version of intellipaat";

10. Write a Hello World program using the variable?


<head><title>Hello World Script using Variable</title></head>
$salutation = “Hello World!”;
echo “<p>$salutation</p>”;

11. Define the Zend Engine?


  • Zend Engine is a runtime engine and compiler which was used internally by PHP. Zend has opcodes that are executed and the HTML generated is sent to the client. PHP Scripts are loaded into memory and compiled into opcodes.
  • The Zend Engine provides many features such as memory and resource management and many other standard services for the PHP language. Its reliability, performance, and extensibility played a significant role in PHP’s increasing popularity.

12. Write the command to run the interactive PHP shell from the CLI (command-line interface)?


Write the following code in the CLI:

php -a

13. How to display the output directly to the browser with the use of PHP?

Answer: Use the special tags <?= and ?> to display the output directly to the browser.

14. PHP supports multiple inheritances or not?

Answer: No, PHP supports only single inheritance and only one single class is used to extend a class using the keyword ‘extended.

15. Tell me the main difference between PHP 4 and PHP 5?

Answer: PHP 5 offers additional features of OOP (Object Oriented Programming) than PHP 4.

16. What do you understand about a final class and a final method?

Answer:‘final’ keyword is introduced in PHP5.

A final class cannot be extended and a final method cannot be overridden.

17. Define Echo vs print statement.


  • echo() and print() are language constructs in PHP, which are used for output strings. The speed of both statements is almost the same and good enough.
  • print() cannot take multiple expressions, whereas echo() can take multiple expressions.
  • Print return true or false which means success or failure, whereas echo doesn’t return true or false.

18. What are the different types of errors in PHP?

Answer: Warnings, Notices, and Fatal errors are the types of errors in PHP.


Warnings occur when calling include() a file, which does not exist. By default, errors are displayed to the user.


Notices are for non-critical errors. For example: accessing a variable that has not yet been defined. These types of small errors are not displayed to the user but whenever it’s required, you can change this default behavior.

Fatal errors

Fatal errors are critical errors. Example: calling a non-existent class or function. These errors cause the immediate termination of the script.

19. What are the function htmlentities and their importance?

Answer: As the name suggests, the htmlentities() function is used to convert characters to HTML entities.

20. How PHP and HTML are connected with each other?

Answer: HTML can be generated through PHP scripts, and it is also possible to pass pieces of information from HTML to PHP.

21. Which operator is used to compare the objects in PHP?

Answer: The ‘==’ operator is used to test if two objects are instanced from the same class with the same attributes and equal values. If two objects are referring to the same instance of the same class then we can test by the use of the identity operator ‘===’.

22. What is the library that is used for pdf in PHP?

Answer: The PDFlib library Version 6 is used for the PDF functions in PHP to create PDF files.

There is also an FPDF which is a PHP class and allows generating PDF files with pure PHP (without using the PDFlib library).

FPDF stands for Free PDF used for any kind of usage and also you can modify it to your needs.

23. Brief of the new features of PHP7?


  • Improved performance of Zend Engine 3
  • 64-bit integer support on Windows
  • AST-based compilation process
  • Newly added Closure::call()
  • Declarations of the return type
  • Unicode codepoint escape syntax
  • integer, float, string, and boolean declarations.

24. Which type of operation is required to pass the values through a form or an URL?

Answer: To pass values through a form or an URL, we need to encode and decode them using htmlspecialchars() and urlencode().

25. What is the full form and meaning of MIME?

Answer: MIME – Multi-purpose Internet Mail Extensions

MIME is the standard way of classifying file types over the Internet.

A MIME has two parts: a type and a subtype and they are separated by a slash (/).

26. How to execute a PHP script using the command line?

Answer: SAPI (Server Application Programming Interface) is used to execute a PHP script. Using SAPI command, the PHP code can be passed to execute directly.


Php –r ‘print_r(get_defined_constanrs());’

In a shell, PHP –v will display whether the SAPI is CLI or CGI

27. Explain the htaccess and its use?

Answer: htaccess files are configuration files of Apache Server. These files provide a way to make configuration changes on a per-directory basis.

These .htaccess files are used to change the features and functionality of the Apache webserver.

  • htaccess file is used for URL rewrite.
  • htaccess file can restrict some IP addresses.
  • These files are used to protect the site password.

*On the restricted IP addresses, the site will not open.

28. How to use image function in PHP?

Answer: A library named GD library is used to execute image functions.

29. What is meant by PEAR in PHP?

Answer: PEAR is used for “PHP Extension and Application Repository”. PEAR is used to provide:

  • PEAR is a system to use for package maintenance and code distribution.
  • A structured library with open-sourced code for PHP users.
  • A different style for writing PHP code.
  • PHP Extension Community Library (PECL)
  • PHP Foundation Classes (PFC)
  • Mailing lists, download mirrors, and websites to support the PEAR community.

30. What’s the output buffering in PHP?

Answer: Output buffering in PHP is used to buffer a script’s output. This buffer executes before returning it to the client. Sending to output is by choice because Output buffers are stackable.

31. Explain the session in PHP.

Answer: Whenever a new user logs in to the application, they must need to enter details that are usually stored in a session variable. This detail is then available to all pages in one application. PHP Sessions work using a unique id for each visitor.

32. How to display text using a PHP script?

Answer: Two methods are available to do this:

<!--?php echo "Method 1"; print "Method 2"; ?-->

33. How to find the number of days between two given dates in PHP?

Answer: You can use the code as shown below to find the start date and end date

$date2= strotime($end_date);
$date_diff = (($date1)- ($date2)) / (60*60*24)

34. What is Memcache?

Answer: Memcache is a technology that is used to cache objects in memory to increase the speed of your web application so that they can get to them really fast. It is used by sites such as, and Also, it is widely recognized as an essential ingredient in scaling any LAMP.

35. Give the statements that are used to connect PHP and MySQL.

Answer: Below statements are used to connect PHP with MySQL:

$conn = mysql_connect('localhost');
echo $conn;

This statement gives the resource of the local host. Other different ways to connect to the database and are as follows:


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

Answer: Open the PHP CLI (Command Line Interface) program.

Write the PHP script file name.

For example: “php myScript.php”, “PHP” is the command to invoke the CLI program.

*Note- If your PHP script was written for the Web CGI interface, it may not execute in the command line environment.

37. Please write the differences between the $message and $$message?


  • $$message can be used to store the variable of a variable, while $message is used to store variable data.
  • Data stored in the $$message can be changed dynamically, while data stored in the $message is fixed.
  • $$message is a variable of another variable and $message is a variable.


$Message = "YOU";
$you= "Me";
echo $message //Output:- you
echo $$message //output :-Me

38. Why PHP is called a Scripting language?

Answer: PHP is a general-purpose language, which is used to write scripts. Scripts are files that consist of a set of instructions. Scripts are used to tell the computer to execute the file and print the output on the screen.

39. How to display information of a variable that is readable by a human in PHP?

Answer: We use print_r() to display a human-readable result.

40. Write the difference between PHP and JavaScript?

Answer: PHP is a server-side scripting language, which means that it is not allowed to interact directly with the user.

Whereas, JavaScript is a client-side scripting language, that makes it possible to directly interact with the user.

41. What is the use of ODBC in PHP?

Answer: ODBC stands for “Open Database connectivity”, which allows the user to communicate with other databases like IBM DB2 and Access. PHP supports many databases like Microsft SQL Server, dBase, Oracle, etc. Other databases like filePro, FrontBase, and InterBase can be used with ODBC connectivity.

42. The function file_get_contents() is useful for?

Answer: Function file_get_contents() is used to read a file and store it in a string variable.

43. What’s difference between require(), require_once(), and include()?


  • require() is used to include and evaluate a specific file. If the file is not found, it gives a Fatal Error.
  • require_once() only includes the file which is being included once. It is recommended for the files where you have lots of functions stored.
  • include() is used to include the file, and if the file is not found, it gives a warning to the user.

44. PHP is an open-source language, therefore is there any support available to use it?

Answer: PHP is an open-source language, and there is a vast community of developers and programmers to support it.

45. How to run PHP?

Answer: The steps are as follows:

  • Set up the web environment.
  • Set up the web servers. Mostly used web server is Apaches. IIS (Internet information server) provided by Microsoft also can be used.
  • Install the Web server and PHP
  • Update and administer the system for changes.

46. Tell me the function which gives us the number of affected entries by a query?

Answer: mysqli_affected_rows() return the number of entries affected by an SQL query.

47. Difference between echo, print, and printf()?


  • Echo is used to print out a string and shows the content of the message written.
  • print is a construct, it returns TRUE and FALSE as per the output.
  • Printf() is a function and allows the string output to be formatted. It is the slowest medium to print the data out.

48. How to check whether the value of a given variable is a number?

Answer: The function is_numeric() is used to check whether it is a number or not.

49. What is the use of unlink() function?

Answer: The unlink() function is for file system handling. It deletes the file given as an entry.

50. Why IDE is recommended in PHP programming?

Answer: IDE (Integrated Development Environment) is a framework for developing applications. The features of IDE are:

  • Debugging
  • Preview
  • Testing
  • FTP
  • Project management
  • Backups

51. Difference between PHP statement and PHP script?

Answer: PHP statements are a set of instructions used to tell PHP to perform an action.

PHP script consists of a series of PHP statements that is used for execution.


PHP statement: echo “Hi”;
PHP script:
if (time = midnight)
put on pajamas;
brush teeth;
go to bed;


All the PHP questions and answers we have mentioned here are purely technical because, in the interview, you are supposed to give logical answers. During the interview, the interviewer may also give you a problem and ask you to write code, so there you need to provide the solution as soon as possible. It interviews most questions are asked from basic programming, so make sure that you go through all the basics of PHP before you appear in the interview. And also make sure that you do not mention those tools on which you have never worked before.

If you like this article or have any suggestions, then feel free to comment down below.

People are also reading:

Author: Paridhi Joshi

Paridhi Joshi is an expert web content manager with significant experience in content creation. Professionally she is dedicated to staying up to date with the latest trends and technologies in content writing and committed to bringing state-of-the-art web approaches to the workplace. She is an efficient multi-tasker who can complete multiple projects under strict deadlines.

Leave a Reply

Your email address will not be published. Required fields are marked *