PHP Experienced interview questions/PHP Interview Questions and Answers for Freshers & Experienced

What is Spaceship Operator in PHP7

PHP7, introduced a new feature, spaceship operator(<=>),It is used to compare two expressions. It returns -1, 0 or 1 when first expression is respectively less than, equal to, or greater than second expression.

echo 1 <=> 2; //ouputs -1 (as 1 is less than 2 , so it returns -1)
echo 1 <=> 1; //outputs 0 (as 1 is equal to1 , so it returns 0)
echo 2 <=> 1; //outputs 1 (as 2 is greater than 1 , so it returns 1)

What is Memcache?

Garbage collection in PHP refers to allocating and deallocating of space due to repeated use of a program. Many times, unnecessary space is consumed when a resource is orphaned after being used. The garbage collector in PHP ensures that these kinds of unwanted space consumption are minimized.

What is garbage collection in PHP?

Garbage collection in PHP refers to allocating and deallocating of space due to repeated use of a program. Many times, unnecessary space is consumed when a resource is orphaned after being used. The garbage collector in PHP ensures that these kinds of unwanted space consumption are minimized.

What is Zend Engine?

Zend Engine is used internally by PHP as a compiler and runtime engine. PHP Scripts are loaded into memory and compiled into Zend OPCodes.

These OPCodes are executed and the HTML generated is sent to the client.

The Zend Engine provides memory and resource management and other standard services for the PHP language. Its performance, reliability, and extensibility have played a significant role in PHP’s increasing popularity.

How can we increase the execution time of a PHP script?

The default time allowed for a PHP script to execute is 30 seconds mentioned in the php.ini file. The function used is set_time_limit(int sec). If the value passed is ‘0’, it takes unlimited time. It should be noted that if the default timer is set to 30 seconds and 20 seconds is specified in set_time_limit(), the script will run for 45 seconds.
This time can be increased by modifying max_execution_time in seconds. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.

What are the steps to create a new database using MySQL and PHP?

There are four basic steps that are used to create a new MySQL database in PHP. They are as follows:
First, a connection is established to the MySQL server using the 1.PHP script.
2.Second, the connection is validated. If the connection is successful, then you can write a sample query to verify.
3. Queries that create the database are input and later stored into a string variable.
4. Then, the created queries are executed one after the other.

What is meant by urlencode and urldocode?

In PHP, the urlencode() function is one that can be conveniently used to encode any string before actually using it as part of the URL in a query. This function is a very efficient way to pass variables onto the next page. Whereas, the urldecode() function is used to decode the above-encoded string into a readable format.

Differentiate between compile-time exception and runtime exception in PHP.

As the name suggests, if there is an occurrence of any sort of exception while the script is being compiled, it is called a compile-time exception. The FileNotFoundException is a good example of a compile-time exception.

An exception that interrupts the script while running is called a runtime exception. The ArrayIndexOutOfBoundException is an example of a runtime exception.

What is the use of session_start() and session_destroy() functions?

In PHP, the session_start() function is used to start a new session. However, it can also resume an existing session if it is stopped. In this case, the return will be the current session if resumed.
The session_destroy() function is mostly used to destroy all of the session variables as shown below:

Is typecasting supported in PHP?

Yes, typecasting is supported by PHP and can be done very easily. Following are the types that can be cast in PHP:

(int), (integer): Cast to integer
(bool), (boolean): Cast to boolean
(float), (double), (real): Cast to float
(string): Cast to string
(array): Cast to array
(object): Cast to object

Define WSDL,SOAP and REST.

A WSDL is an XML document that describes a web service.

It actually stands for Web Services Description Language.WSDL tells about the functions that you can implement or exposed to the client. For example: add, delete, subtract and so on

SOAP is an XML-based protocol that lets you exchange info over a particular protocol (can be HTTP or SMTP, for example) between applications. It stands for Simple Object Access Protocol and uses XML for its messaging format to relay the information.

REST is an architectural style of networked systems and stands for Representational State Transfer.
It's not a standard itself, but does use standards such as HTTP, URL, XML, etc

What is PHP sessions default timeout.

The default session timeout is 24 minutes (1440 seconds),

however we can change this value by setting session.gc_maxlifetime() in php ini file.

What is difference between strstr and stristr.

strstr and stristr both are used to search for the first occurrence of a string inside another string
Difference :
the strstr function is case sensitive and stristr is case insensitive.
e.g :
$email =
$result = strstr($email , ‘@’); //output :

How can we resolve maximum allocation time exceeds error

We can resolve these errors through php.ini file or through .htaccess file.
1. From php.ini file increase the max_execution_time =360 (or more according to need)

and change memory_limit =128M (or more according to need)
2. From php file we can increase time by writing ini_set(‘max_execution_time’,360 ) at top of php page to increase the execution time.
And to change memory_limit write ini_set(‘memory_limit ,128M )
3. From .htaccess file we ncrease time and memory by
<IfModule mod_php5>

php_value max_execution_time 360

php_value m emory_limit 128M

</ IfModule >

What is difference between single quotes and double quotes in php

When string is in single quotes php will not evaluate it . If there is a string with single quotes and if we place a variable in that it would not substitute its value in string, whereas double quotes support variable expansion. If we place variable in double quotes it would substitute its value in string.


$str = 1;
echo '$str is a value'; // OUTPUT : $str is a value
echo "$str is a value"; //OUTPUT : 1 is a value


What is the IonCube PHP loader?

The ionCube Loader is an advanced component used by developers on the server to run encoded files. It protects the source code. When our PHP code gets pre-compiled and encrypted and requires a separate PHP module to load it, ionCube PHP loader will be required at that scenario.

Why we use array_flip

array_flip exchange the keys with their associated values in array ie. Keys becomes values and values becomes keys.

$arrayName = array("course1"=>"php","course2"=>"html");

$new_array = array_flip($arrayName);
[php] => course1

[html] => course2)

Why we use strpos in PHP

Strpos used to find the first occurrence of a string in another string.It return the position of the substring in a string . If the searched string will not exists in the searching string it return false.
Synatx : strpos(‘stringtosearchin’ ,’stringtosearch’);
e.g :

$mystring = ’lets knowit ’;
$find = ‘knowit ’;
$result = strpos($mystring,$find) //OUTPUT : 6

How to get the number of elements in an array

We have two functions to get the number of elements in an array ie count() and sizeof().
Synatx : count ($array_name) and sizeof($array_name)

What is differnce between HTML and XHTML

1 : HTML stands for HyperText Markup Language and an application of SGML(Standard Gneralized Markup Language ).
Whereas XHTML (Extensible Hyper text Markup Language) is an applicati2 :HTML permit the omission of certain tags and use attribute minimization whereas XHTML does not permit the omission of any tag .A XML document must be well formed ,means there must be an end tag for every start tag.on of XML .

What are some of the top Content Management Systems (CMS) used in PHP?

There are many CMS that are used in PHP. The popular ones are as mentioned below:
1. WordPress

What is the use of constructors and destructors in PHP?

Constructors are used in PHP as they allow you to pass parameters when creating a new object easily. This is used to initialize the variables for the particular object in consideration.
Destructors are methods used to destroy an object. Both of these are special methods provided in PHP for you to perform complex procedures using a single step.

What are some of the popular frameworks in PHP?

There are many frameworks in PHP that are known for their usage. Following are some of them:

1. CodeIgniter
2. CakePHP
3. Laravel
4. Zend
5. Phalcon
Yii 2

What is a composer?

It is an application package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software. The composer is developed by Nils Adermann and Jordi Boggiano, who continue to lead the project. The composer is easy to use, and installation can be done through the command line.

What is MVC?

MVC is an application in PHP which separates the application data and model from the view.

The full form of MVC is Model, View & Controller. The controller is used to interacting between the models and views.

What is the meaning of break and continue statements in PHP?

Break: This statement is used in a looping construct to terminate the execution of the iteration and to immediately execute the next snippet of code outside the block of the looping construct.

Continue: This statement is used to skip the current iteration of the loop and continue to execute the next iteration until the looping construct is exited.

How are constants defined in PHP?

Constants can be defined easily in PHP by making use of the define() function. This function is used to define and pull out the values of the constants easily.

Constants, as the name suggests, cannot be changed after definition. They do not require the PHP syntax of starting with the conventional $ sign.

Explain the difference between exec() vs system() vs passthru()?

1. exec() is for calling a system command, and perhaps dealing with the output yourself.
2. system() is for executing a system command and immediately displaying the output - presumably text.
3. passthru() is for executing a system command which you wish the raw return from - presumably something binary.

What exactly is an HTTP request?

The question asks for two major things from a URL – the total number of HTTP requests and the total download size for all requests. The download size is easy enough to understand, but you may be confused by what exactly is meant by an HTTP request. HTTP is the protocol used to communicate on the web. When you visit a webpage, your browser will make an HTTP request to the server that hosts that webpage, and the server on which the webpage is hosted will respond with an HTTP response.

But, what is important to understand here, is that your browser will probably have to make multiple HTTP requests in order to retrieve a single HTML page at a given URL, because that webpage will probably have some CSS files to go along with it, some Javascript files, and probably some images as well. Each one of those resources is a separate HTTP request – 2 image files, 2 Javascript files, and 2 CSS files means 6 separate HTTP requests. In HTTP, only one resource can be requested at a time – so we can not have 1 request for 6 different resources, instead we must have 6 requests for those 6 different resources.
So, for the purpose of this interview question, we have to find out the number of HTTP requests that will be made for a given URL – hopefully what that means is now clear to you. We’ll go more in depth on this later – and show some actual code – as we cover some other things as well.

Explain function call by reference

In case of call by reference, actual value is modified if it is modified inside the function. In such case, we need to use & symbol with formal arguments. The & represents reference of the variable.
function adder(&$str2) {
$str2 .= 'Call By Reference';
$str = 'This is ';
echo $str;

This is Call By Reference

How to export data into an Excel file?

Commonly, the data is obtained in a format supported by Excel. For instance, we can write a .csv file, select a separator between fields (a comma for example), and then proceed to open the file with Excel.

Explain the PHP error 'Parse error in PHP - unexpected T_variable at line x'.

This is a syntax error in PHP which tells us that a mistake at the line x stops parsing and executing the program.

What are 'Traits'?

A mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported is called Traits. It's not possible to instantiate it on its own.

Name the different types of variables in PHP

There are eight data types used to construct variables in PHP −

Integers − these are whole numbers without a decimal point, like 4195.

Doubles − are floating-point numbers, like 3.14159 or 49.1.

Booleans – come with only possible values of either true or false.

NULL − is a special type with only one value: NULL.

Strings − are sequences of characters.

Arrays − are named and indexed set of other values.

Objects − are f programmer-defined classes, which can include
both other kinds of values and functions that are specific to the class.

Resources − are special variables that refer to resources external to PHP (such as database connections).

When should I use require vs. include?

The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.
My suggestion is to just use require_once 99.9% of the time.
Using require or include instead implies that your code is not reusable elsewhere, i.e. that the scripts you're pulling in actually execute code instead of making available a class or some function libraries.

What is the differences between $a != $b and $a !== $b?

!= means inequality (TRUE if $a is not equal to $b) and !== means non-identity (TRUE if $a is not identical to $b).

How can you embed PHP code in an HTML page?

When embedding PHP code with an HTML file, we must use the .php file extension for that file. This allows your webserver to send the file to PHP for processing. If the webserver is configured to use a different extension for PHP files, that extension must be used instead.
We need to use PHP start and end tags to tell the web server where the PHP code starts and ends. There are three styles of start and end tags that PHP parser recognizes.
XML style – Mostly used when when merging PHP with XML or HTML documents
<? php

PHP code


Short style – This is the simplest type, though it is not recommended to avoid interference with XML document declarations.

PHP code goes here


Long style - This style is the longest and matches the tag style used with JavaScript.
<script language="php">

PHP code


What are the popular frameworks in PHP?

Some pCodeIgniter
Zend Framework
Yii 2opular PHP frameworks are:

How to download files from an external server with code in PHP?

We can do it by various methods, If you have allow_url_fopen set to true:
We can download images or files from an external server with cURL() But in this case, curl has been enabled on both servers
We can also do it by file_put_contents()

How can we upload a file in PHP?

For file upload in PHP make sure that the form uses method="post" and attribute: enctype="multipart/form-data". It specifies that which content-type to use when submitting the form.
$target_dir = "upload/";

$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

$uploadOk = 1;

$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

if(isset($_POST["submit"])) {

$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);

if($check !== false) {

echo "File is an image - " . $check["mime"] . ".";

$uploadOk = 1;

} else {

echo "File is not an image.";

$uploadOk = 0;



What is the difference between require() and require_once()?

require() and require_once() both are used for include PHP files into another PHP files. But the difference is with the help of require() we can include the same file many times in a single page, but in case of require_once() we can call the same file many times, but PHP includes that file only single time.

What is the use of the .htaccess file in php?

The .htaccess file is a type of configuration file for use on web servers running the Apache Web Server software. It is used to alter the configuration of our Apache Server software to enable or disable additional functionality that the Apache Web Server software has to offer.

How to get IP Address of clients machine?

If we used $_SERVER[‘REMOTE_ADDR’] to get an IP address, but sometimes it will not return the correct value. If the client is connected with the Internet through Proxy Server then $_SERVER[‘REMOTE_ADDR’] in PHP, it returns the IP address of the proxy server not of the user’s machine.

What is the difference between MyISAM and InnoDB?

There are lots of differences between storage engines. Some are given below:-
MyISAM supports Table-level Locking, but InnoDB supports Row-level Locking
MyISAM designed for the need of speed but InnoDB designed for maximum performance when processing a high volume of data
MyISAM does not support foreign keys, but InnoDB supports foreign keys
MyISAM supports full-text search, but InnoDB does not support this
MyISAM does not support the transaction, but InnoDB supports transaction
You cannot commit and rollback with MyISAM, but You can determine and rollback with InnoDB
MyISAM stores its data, tables, and indexes in disk space using separate three different files, but InnoDB stores its indexes and tables in a tablespace

What is the difference between public, protected and private?

PHP has three access modifiers such as public, private, and protected.
1. public scope of this variable or function is available from anywhere, other classes, and instances of the object.
2. private scope of this variable or function is available in its class only.
3. protected scope of this variable or function is available in all classes that extend the current class including the parent class.

What are the main differences between const vs define

he fundamental difference between const vs define is that const defines constants at compile time, whereas define defines them at run time.
const FOO = 'BAR';
define('FOO', 'BAR');

// but
if (...) {
const FOO = 'BAR'; // Invalid
if (...) {
define('FOO', 'BAR'); // Valid

What are some of the common applications of PHP?

PHP is commonly used to perform −

1. system functions. It can create, open, read, write, and close to files on a system.
2. handling forms. It can help. Collect data from files, save data to a file, send data through email, return data to the user, etc.
3. tasks that involve adding, deleting, and modify elements within your database
4. accessing cookies variables and set cookies.
5. user restriction to access some pages of your website
6. data encryption

Differentiate between echo and print()

echo and print are more or less the same. They are both used to output data to the screen.
The differences are:
1. echo has no return value while print has a return value of 1 so it can be used in expressions.
2. echo can take multiple parameters (although such usage is rare) while print can take one argument.
3. echo is faster than print.

What did the acronym PHP originally stand for?

Initially, PHP stood for Personal Home Page, but it now stands for the recursive acronym for PHP: Hypertext Preprocessor.

Who do we know as the father of PHP?

Rasmus Lerdorf who created the language in 1994.

R4R Team
R4R provides PHP Freshers questions and answers (PHP Interview Questions and Answers) .The questions on website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,PHP Experienced interview questions,PHP Freshers & Experienced Interview Questions and Answers,PHP Objetive choice questions and answers,PHP Multiple choice questions and answers,PHP objective, PHP questions , PHP answers,PHP MCQs questions and answers Java, C ,C++, ASP, C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for PHP fresher interview questions ,PHP Experienced interview questions,PHP fresher interview questions and answers ,PHP Experienced interview questions and answers,tricky PHP queries for interview pdf,complex PHP for practice with answers,PHP for practice with answers You can search job and get offer latters by studing .learn in easy ways .