PHP Interview Questions

PHP Interview Questions: The questions concerning to PHP, which are asked in an interview decides a candidate’s occupation and fortune in the industry. As long as the just right answers to PHP, interview questions raised by an interviewer generate scope for winning interview endeavors. The below mentioned PHP interview questionnaire is the work of Aptron's PHP specialists, PHP experts, and PHP trainers who have added their best of knowledge and experience in preparing PHP interview questions and answers for freshers, and skill candidates. The questionnaire offers detailed answers to essential and advanced PHP interview questions. It assists job applicants to crack interviews and find applicable answers to their doubts or confusions. The PHP Interview Questions sum up all verticals accessible in the PHP technology.

php interview questions

About PHP

Hypertext Preprocessor (or simply PHP) is a known to be a general-purpose programming language designed for web development. PHP code may be carried out with a command line interface (CLI), fixed into HTML code, or utilized in combination with a variety of web template systems, web content management systems, and web frameworks. PHP code is more often than not processed by a PHP interpreter implemented as a web server or Common Gateway Interface (CGI) executable. The web server yields the results of the construed and executed PHP code, which might be any kind of data, such as developed HTML code or binary image data. PHP can be utilized for many programming tasks outside of the web context.

PHP Interview Questions And Answers

1. What is PHP?

PHP is one of the popular server-side scripting languages for developing a web application.

The full form of PHP is Hypertext Preprocessor. It is used by embedding HTML for creating dynamic content, communicating with a database server, handling session etc.

2. Why do we use PHP?

There are several benefits of using PHP. First of all, it is totally free to use. So anyone can use PHP without any cost and host the site at a minimal cost.

It supports multiple databases. The most commonly used database is MySQL which is also free to use. Many PHP frameworks are used now for web development, such as CodeIgniter, CakePHP, Laravel etc.

These frameworks make the web development task much easier than before.

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

To be able to display the output directly to the browser, we have to use the special tags <?= and ?>.

4. Is multiple inheritance supported in PHP?

PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword 'extended'.

5. What is the meaning of a final class and a final method?

'final' is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overridden.

6. How is the comparison of objects done in PHP?

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

7. How can PHP and HTML interact?

It is possible to generate HTML through PHP scripts, and it is possible to pass pieces of information from HTML to PHP.

8. What type of operation is needed when passing values through a form or an URL?

If we would like to pass values through a form or an URL, then we need to encode and to decode them using htmlspecialchars() and urlencode().

9. How can PHP and Javascript interact?

PHP and Javascript cannot directly interact since PHP is a server side language and Javascript is a client-side language. However, we can exchange variables since PHP can generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.

10. What is needed to be able to use image function?

GD library is needed to execute image functions.

11. What is the use of the function 'imagetypes()'?

imagetypes() gives the image format and types supported by the current version of GD-PHP.

12. What are the functions to be used to get the image's properties (size, width, and height)?

The functions are getimagesize() for size, imagesx() for width and imagesy() for height.

13. List some of the features of PHP7.

  • Scalar type declarations
  • Return type declarations
  • Null coalescing operator (??)
  • Spaceship operator
  • Constant arrays using define()
  • Anonymous classes
  • Closure::call method
  • Group use declaration
  • Generator return expressions
  • Generator delegation
  • Space ship operator

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

Echo can output one or more string but print can only output one string and always returns 1.

Echo is faster than print because it does not return any value.

15. What is the difference between $message and $$message?

$message stores variable data while $$message is used to store variable of variables.

$message stores fixed data whereas the data stored in $$message may be changed dynamically.

16. What is the use of header() function in PHP?

The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can't print any HTML element before using this function.

17. Differentiate between require and include?

Require and include both are used to include a file, but if data is not found include sends warning whereas require sends Fatal error.

18. Name some of the constants in PHP and their purpose.

  1. _LINE_ – It represents the current line number of the file.
  2. _FILE_ – It represents the full path and filename of the file. If used inside an include,the name of the included file is returned.
  3. _FUNCTION_ – It represents the function name.
  4. _CLASS_ – It returns the class name as it was declared.
  5. _METHOD_ – It represents the class method name.

19. How is it possible to know the number of rows returned in the result set?

The function mysqli_num_rows() returns the number of rows in a result set.

20. Which function gives us the number of affected entries by a query?

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

21. What is the difference between mysqli_fetch_object() and mysqli_fetch_array()?

The mysqli_fetch_object() function collects the first single matching record where mysqli_fetch_array() collects all matching records from the table in an array.

22. Which cryptographic extension provide generation and verification of digital signatures?

The PHP-OpenSSL extension provides several cryptographic operations including generation and verification of digital signatures.

23. When is a conditional statement ended with endif?

When the original if was followed by: and then the code block without braces.

24. What are the differences between session and cookie?

The session is a global variable which is used in the server to store the session data. When a new session creates the cookie with the session id is stored on the visitor's computer. The session variable can store more data than the cookie variable.

Session data are stored in a $_SESSION array and Cookie data are stored in a $_COOKIE array. Session values are removed automatically when the visitor closes the browser and cookie values are not removed automatically.

25. What is a persistence cookie?

A cookie file that is stored permanently in the browser is called a persistence cookie. It is not secure and is mainly used for tracking a visitor for long times.

This type of cookie can be declared as follows,

setccookie ("cookie_name", "cookie_value", strtotime("+2 years");

26. Which PHP global variable is used for uploading a file?

$_FILE[] array contains all the information of an uploaded file.

The use of various indexes of this array is mentioned below:

$_FILES[$fieldName][‘name'] – Keeps the original file name.

$_FILES[$fieldName][‘type'] – Keeps the file type of an uploaded file.

$_FILES[$fieldName][‘size'] – Stores the file size in bytes.

$_FILES[$fieldName][‘tmp_name'] – Keeps the temporary file name which is used to store the file in the server.

$_FILES[$fieldName][‘error'] – Contains error code related to the error that appears during the upload.

27. What is meant by public, private, protected, static and final scopes?

  • Public– Variables, classes, and methods which are declared public can be accessed from anywhere.
  • Private– Variables, classes and methods which are declared private can be accessed by the parent class only.
  • Protected– Variables, classes, and methods which are declared protected can be accessed by the parent and child classes only.
  • Static– The variable which is declared static can keep the value after losing the scope.
  • Final– This scope prevents the child class to declare the same item again.

28. What is garbage collection?

It is an automated feature of PHP.

When it runs, it removes all sessions data which are not accessed for a long time. It runs on /tmp directory which is the default session directory.

29. What is URL rewriting?

Appending the session ID in every local URL of the requested page for keeping the session information is called URL rewriting.

The disadvantages of this methods are, it doesn't allow persistence between the sessions and, the user can easily copy and paste the URL and send to another user.

30.What is PDO?

The full form of PDO is PHP Data Objects.

It is a lightweight PHP extension that uses consistence interface for accessing the database. Using PDO, a developer can easily switch from one database server to the other. But it does not support all the advanced features of the new MySQL server.

Career scopes and salary scale

The average joblessness rate is likely to hoist in the job marketplace, however, the obligation of PHP developers, PHP programmers, and PHP engineers are at the upper side. Applicants with in-depth acquaintance and skill-based experience in PHP technology are expected to take the full improvement of technological expansion. Besides, PHP has occupied the highest place in the arena of programming languages as it offers a range of features to the developers. A PHP programmer is expected to take pleasure in minimum salary of 40, 000 dollars per annum. However, the salary of an experienced PHP developer can rise to double the figure mentioned before. The salaries are totally dependent upon the location, business, and the company’s requirements.


The article ‘PHP interview questions’ has answered each advanced PHP interview questions. In addition, the considerate structured of the PHP interview questions for experienced is being intended by our experts, which might have assisted candidates in getting answers to all their doubts and not clear ideas. Even then, if learners are still stressed with their confusions and doubts, they may drop in a message about PHP query or to our experts regarding PHP interview questions for experienced professionals. Our trainers would be happy to assist and resolve all your PHP-programming issues of the students. Join PHP Training in Noida, PHP Training in Delhi, PHP Training in Gurgaon

Enquiry Now
Quick Enquiry Form


B-10, SECTOR-2
NOIDA - 201301, U.P. (INDIA)
Contact Number : +91-706-527-3000


Bhikaji Cama Place New Delhi,
Contact Number : +91-706-527-1000

APTRON Gurgaon