PHP Interview Questions

Core PHP Interview Questions

  • Tony Thomas
  • 30th Apr, 2021

About PHP

PHP stands for Hypertext Preprocessor is a server-side scripting language. PHP is among one of the most popular programming languages on the World Wide Web. This server-side programming language is highly flexible and loaded with many innovative features to create Dynamic websites. With PHP, you can simply build a website that is interactive for visitors to your site. There are many people that are programmers that can create PHP forms for their website without a generator, but not everyone can do that. Some of the best examples of websites that are actually written in PHP are Facebook, Wikipedia, Quora, etc.

PHP Interview Questions

1) What is PHP?

PHP Stands for PHP Hypertext Preprocessor. It is an open-source scripting language, widely used for web development. PHP code is executed on the server, and the result is returned to the browser as plain HTML. The PHP was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1994 with the file extension of ".Php".

2) What is $$ in PHP?

The $$ in PHP is also known as $$ variable is a reference variable that stores the value of the $ variable inside it.

3) What is php full form?

The Full Form of PHP is PHP Hypertext Preprocessor. It is a general-purpose scripting language, especially used for web development.

4) What is PEAR in PHP?

PEAR stands for PHP Extension and Application Repository it provides a higher level of programming for all web developers.

5) What is difference between array_merge and array_combine in php?

array_combine(): It is used to creates a new array where the key of one array is used as keys and the value of another array is used as values.

array_merge(): It merges one or more than one array appending the value of one array at the end of the first array.

Download Free : PHP Interview Questions PDF

6) What is use of sizeof function in php?

The sizeof() function is used to return the number of elements present in an array.

7) How to display array value in php?

By using print_r() or var_dump() we can display array value in php.

8) What is the use of strlen( ) function in php?

strlen( ) is a function used to return the length of a string in PHP.

9) How to create a mysql connection in PHP?

There are two methods to create a MySQL connection in PHP:

  • With PHP’s MySQLi Extension
  • With PHP Data Objects (PDO)

10) What is use of str_word_count() function in php?

str_word_count() function is used to count the number of words present in a given string in PHP.

Take Free: Php MCQ & Quiz

11) What is the use of strpos( ) function in php?

strpos( ) function is used to find the position of the first occurrence of a string inside another string in PHP.

12) How can you enable error reporting in PHP?

You can enable error reporting in PHP by adding the following in your code. ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

13) List some popular Content Management Systems (CMS) in PHP?

Some popular Content Management Systems (CMS) in PHP are:

  • WordPress
  • Joomla
  • Drupal
  • OctoberCMS
  • OpenCart
  • ExpressionEngine
  • PyroCMS
  • Magento
  • Craft CMS
  • TYPO3

14) What the PHP-FIG?

PHP-FIG is also known as PHP Framework Interoperability Group is used to advance the PHP ecosystem such that people and projects are brought together for better outcomes.

15) What is composer?

A composer is a tool for dependency management in PHP. It allows us to declare the libraries our project depends on and it will manage (install/update) them for us. Composer is not a package manager in the same sense as Yum or Apt are. Yes, it deals with "packages" or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project.

16) What are magic constants in PHP?

Magic constants in PHP are the predefined constants, which get changed on the basis of their use. It starts with a double underscore (__) and ends with a double underscore. Magic constants are similar to other predefined constants but as they change their values with the context, they are called magic constants.

17) How to get ip address of user in PHP?

You can get ip address in PHP with the help of REMOTE_ADDR.

<? php. echo 'User IP Address - '. $_SERVER['REMOTE_ADDR']; ?>

18) What is namespace in PHP?

Namespaces in PHP are designed to solve the two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions.

  • Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
  • Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving the readability of source code.

19) What is a session in PHP?

A session in PHP is used for the purpose of storing the data on the server such that it can be accessed and used across multiple pages.

20) Explain type juggling in PHP?

Type Juggling is used in PHP to avoid the use of explicit type definition in a variable declaration, as the variable's type is determined by the context in which it is used.

21) What is the difference between var_dump() and print_r()?

var_dump function is used to display structured information about a variable with its type and value.

print_r() is used to display information that is easily readable by humans.

22) What is the difference between mysql_fetch_object() and mysql_fetch_array()?

Mysql_fetch_object is used to return the result as an object.

Mysql_fetch_array is used to return the result in the form of an array.

23) What is difference between strstr() and stristr()?

stristr() is a case-insensitive function that is used to search a string inside another string.

strstr() is a case-sensitive function that is used to search a string inside another string.

24) What is use of nl2br() function in PHP?

The nl2br() function in PHP is used to inserts HTML line breaks (
) in front of each newline (\n) in a string.

25) How to define constant in PHP?

You can define a constant in PHPcby using define() function.

Syntax: define(name, value, case-insensitive)

26) How do you register a variable in PHP session?

27) What are different types of errors available in PHP?

There are four different types of errors in PHP.

  • Warning Error.
  • Notice Error.
  • Parse Error.
  • Fatal Error.

28) What is use of GD library in PHP?

GD library is an open-source code library used for creating images dynamically in PHP. It is generally used to generate charts, graphics, thumbnails on the fly.

29) What is use of PHP.ini file?

php. ini file is used as the default configuration file for running applications that are based on PHP.

30) What is default time and path of session in PHP?

The default time is 24 minutes or 1440 seconds and the default path of the session is /var/lib/php5/sessions in PHP.


PHP T_PAAMAYIM_NEKUDOTAYIM is the token name used for double colon( :: ) in PHP.

32) What is the factory pattern?

A Factory Pattern is a method that is used to define an interface or abstract class for creating an object without exposing the creation logic to the client.

33) What is the difference between == and === in PHP?

The " == " operator casts between two different types if they are different. The " === " operator performs a typesafe comparison i.e. it will only return true if both operands have the same type and value.

34) How to pass data in header while using curl?

-H flag is used to pass the data in the header while using the header with curl.

35) What is stdClass in PHP?

The stdClass is the empty class that is used to cast other types to object in PHP.

36) What is use of Null Coalesce Operator?

The Null Coalesce Operator is used to replace the ternary operation in conjunction with isset() function.

37) What is urlencode() and urldecode()?

urlencode is the PHP function that is used to encode a string that would be used in a query part of a URL.

urldecode is the PHP function that is used to decode the query part of a URL.

38) How to create and destroy a cookie in PHP?

setcookie(name, value, expire, path, domain, secure, http only); is used for creating a cookie.

setcookie() function with an expiration date in the past is used for deleting a cookie.

39) What are constructor and destructor in PHP?

Constructor is used to initializing the instance of a class automatically when the object is created.

Destructor is used to de-initialize objects already existing to free up memory for new accommodation.

40) What is a lambda function in PHP?

A lambda function is an anonymous function in PHP used to store a variable and passed as an argument to other functions.

10 comment(s) :

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.