DEV Community


Posted on

PHP Interview Questions

Below are the few Latest Php programming interview questions

  1. What is PHP?

PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for creation of dynamic web applications.It was developed by Rasmus Lerdorf also know as Father of PHP in 1994.

PHP is a loosely typed language, we didn’t have to tell PHP which kind of Datatype a Variable is. PHP automatically converts the variable to the correct datatype , depending on its value.


T_PAAMAYIM_NEKUDOTAYIM is scope resolution operator used as :: (double colon) .Basically it used to calling static methods/variables of a Class.

Example usage:-


  1. What is the difference between == and === operator in PHP ?

In PHP == is equal operator and returns TRUE if $a is equal to $b after type juggling and === is Identical operator and return TRUE if $a is equal to $b, and they are of the same data type.

Example Usages:

$a=true ;
// Below condition returns true and prints a and b are equal
echo "a and b are equal";
echo "a and b are not equal";
//Below condition returns false and prints a and b are not equal because $a and $b are of different data types.
echo "a and b are equal";
echo "a and b are not equal";

  1. What is session in PHP. How to remove data from a session?

As HTTP is state protocol.To maintain states on server and share data across multiple pages PHP session are used.PHP sessions are simple way to store data for individual users/client against a unique session ID.Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data,if session id is not present on server PHP creates a new session, and generate a new session ID.

Example Usage:-

//starting a session
//Creating a session

//checking session
echo "logged In";

//un setting remove a value from session

// destroying complete session


  1. How to register a variable in PHP session ?

In PHP 5.3 or below we can register a variable session_register() function.It is deprecated now and we can set directly a value in $_SESSION Global.

Example usage:

// Starting session
// Use of session_register() is deprecated
$username = "PhpScots";
// Use of $_SESSION is preferred
$_SESSION["username"] = "PhpScots";

Also Read Laravel interview questions

  1. Where sessions stored in PHP ?

PHP sessions are stored on server generally in text files in a temp directory of server.
That file is not accessible from outside word. When we create a session PHP create a unique session id that is shared by client by creating cookie on clients browser.That session id is sent by client browser to server each time when a request is made and session is identified.
The default session name is “PHPSESSID”.

  1. What is default session time and path in PHP. How to change it ?

Default session time in PHP is 1440 seconds (24 minutes) and Default session storage path is temporary folder/tmp on server.

You can change default session time by using below code

// server should keep session data for AT LEAST 1 hour
ini_set('session.gc_maxlifetime', 3600);

// each client should remember their session id for EXACTLY 1 hour

  1. What are PHP Magic Methods/Functions. List them.

In PHP all functions starting with __ names are magical functions/methods. Magical methods always lives in a PHP class.The definition of magical function are defined by programmer itself.

Here are list of magic functions available in PHP

__construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone() and __debugInfo() .

  1. What is difference between include,require,include_once and require_once() ?

Include :-Include is used to include files more than once in single PHP script.You can include a file as many times you want.

Syntax:- include(“file_name.php”);

Include Once:-Include once include a file only one time in php script.Second attempt to include is ignored.

Syntax:- include_once(“file_name.php”);

Require:-Require is also used to include files more than once in single PHP script.Require generates a Fatal error and halts the script execution,if file is not found on specified location or path.You can require a file as many time you want in a single script.

Syntax:- require(“file_name.php”);

Require Once :-Require once include a file only one time in php script.Second attempt to include is ignored. Require Once also generates a Fatal error and halts the script execution ,if file is not found on specified location or path.

Syntax:- require_once(“file_name.php”);

Read More Questions from

Top comments (5)

vijaykhatri96 profile image
Vijay Singh Khatri

Hi Sharad,
You have shared very informative and basic interview question which are useful for fresher, Who is at the starting point of their career if a developer a looking for the interview question then can go with this post.

mohithsharma profile image


Thanks for this informative and useful article. Here is my pick for PHP Interview Questions if you are preparing for the interview.

gangbchb profile image

Find vulnerabilities that you thought were fixed in your web apps using Detectify and the power of our crowd. Go hack yourself with

satyam_prg profile image
Satyam Jaiswal

Best Interview Questions for Freshers. Learn here top mcqs on php.