Online Tutorials & Training Materials |
Register Login

PHP Interview Questions

PHP Interview FAQ's

1) What is _FILE_ constant?

A _FILE_ constant contains the filename and the full path of the file. If the constant is used inside include, the included file name is returned.

2) Why is the break statement used?

The break statement terminates the switch statement or for loop and transfers the execution to the statement just after the switch or the for loop.

3) Explain the use of foreach loop in PHP?

The 'foreach' statement is used to loop through each key pair or value pair in an array. For every pass, the value of the current array element is assigned to $value and the array pointer is moved by one till the last array element is reached.

4) How can you identify a string within a string in PHP?

To search for another string or a character within a string, the function that is used is strpos(). If there is a match, the function returns the position of the match and otherwise, it returns FALSE.

5) How to redirect a page using PHP?

The browser obtains raw HTTP headers from the PHP header() function which is used to redirect it to some other location. After calling the header() function, the exit() function is used to prevent the rest of the code from getting parsed.

6) What is the difference between include() and require() functions?

In case of a problem in loading a file, the require () causes a fatal error stops the script's execution. In case of the same problem, the include() issues a warning but the execution of the script continues.

7) How can you set cookies using PHP?

The setcookie() function is used to set a cooking and the function is called separately to set each cookie. The syntax is: setcookie(name, value, expire, path, domain, security);

8) How is a cookie deleted?

The setcookie() function is called with only the name argument for deleting a cookie.

9) What is the use of final keyword?

The final keyword prefixes the definition of a method with itself and prevents the method from being overriden by a child class. If a class is defined as final, it means that the class cannot be extended.

10) How will you parse an XML document using PHP?

The SimpleXML module of PHP 5 helps to parse an XML document. The module turns the XML document into an object providing structured access to the XML. To create an object from the XML document that is stored inside a string, the string is passed to simplexml_load_string( ). It returns the SimpleXML object.

11) What is the purpose of the unlink() function?

The unlink() function is used to delete any file. It returns TRUE in case of success and FALSE in case of failure.

12) How is the ternary conditional operator used in PHP?

It has three expressions- one condition along with two operands that describe the function to be performed according to whether the said condition is true or false.
Condition? Operand_1 : Operand 2;

13) What is a persistent cookie?

A persistent cookie is one that remains stored in the cookie file unlike normal cookies that get erased when the browser is closed. Persistent cookies are created in the same way that temporary cookies are created; you just have to set an expiry date for the cookie to persist for that time period.

14) How does a session end?

A session ends on its own when the execution of the PHP script finishes. A session can also be ended manually by using the session_write_close() function.

15) What is the difference between for and foreach?

The PHP for loop executes a code for a certain number of times and is used only when it is known beforehand how many times the block of code has to be run.


for ($m=0; $m<=5; $m++); {
echo "The result is : $m"; }

The foreach loop works on arrays only and loops through each of the key/value pairs in an array.


foreach ($m as $value) {
echo "$value"; }

16) Explain whether it is possible to share a single instance of a Memcache between multiple PHP projects?

Yes, it is possible. Memcache is a memory space and can be run on multiple servers. Two independent Memcache processes can be run on the same host. Only if you are using partitioned data, then you need to know the instance in which you have to put the data or the one from which you have to get the data.

17) What does $GLOBALS mean?

$GLOBALS is a super global variable in PHP that can be used to access any global variable in a PHP script.

18)What is the difference between unset() and unlink()?

The unset() function sets the value of a variable to 'undefined' and the unlink() function deletes any file that is passed to it from the system.

19) What are the error types in PHP and how do they differ?

There are three main error types in PHP-

  • Notice: It refers to any simple error, like trying to access any undefined variable, that occurs during the execution of the script.
  • Warning: It is a more serious error than a notice but does not halt the execution of the script. For example, an include() a non-existing file.
  • Fatal: This is a major error that terminates the execution of the script. Examples of such an error would be to require() a file which doesn't exist or trying to access the property of an object that doesn't exist.

20) What is the difference between GET and POST?

The differences between GET and POST are-

  • GET can transfer not more than 2048 characters, POST has no constraints like that and can handle larger amount of data.
  • GET can transfer nothing but ASCII data while POST allows binary data too.
  • GET is for extracting data while POST is to insert and update.

21) What are Traits in PHP?

Trait is a very powerful feature of PHP that lets you create a reusable code which is essential in a language like PHP that does not support multiple inheritance.

22) What are _construct() and _destruct() methods in PHP?

The _construct() method signifies the constructor that is called immediately after the creation of a new instance variable in a class to initialize the properties of the class. The destructor method _destruct() does not take any parameter and is called when an obbject is to be deleted.

23) What are the 3 scope levels available in PHP and how would you define them?

The three scope levels are-

  • Private- The object is visible only in the class in which it is created.
  • Public- The object is visible to any code that accesses the class.
  • Protected- The object is visible to the parent class and child classes of the class.

24) What are getters and setters?

Getter is an object method that lets you 'get' or retrieve a property while Setter is another object method that lets you 'set' the value of a property.

25) What is 'echo' in PHP?

The echo() function is a slightly faster print function that can output multiple strings.

1046 results
  • Laravel Interview Questions and Answers
    What is Laravel? n nLaravel is a structure that allows a user to choose and create programs. Everything from giving a form to software and joining it with different application programs is covered by...
  • Posted in: Articles » » | By: rekha | Date: 15 Jan 2019 6:04 am | Comments (0)
  • Hive Interview Questions and Answers
    What is Hive? n nHive is a tool to perform ETL (extract, transform and load) and Data warehousing functions. It was developed as a sub-project of Hadoop Distributed File System (HDFS). Hive makes...
  • Posted in: Articles » » | By: vaibhav gupta | Date: 14 Feb 2019 6:43 am | Comments (0)
  • Appium Interview Questions and Answers
    What is Appium testing? n nIt is an open source testing framework used for mobile apps. It is used to test the user interfaces of the mobile web, native and hybrid applications. These tests can be...
  • Posted in: Articles » » | By: Shalesh Singh | Date: 11 Feb 2019 1:34 pm | Comments (0)
  • Advanced JavaScript Interview Questions and Answers
    1. How to validate email addresses in JavaScript? n nThe most used method for validating email addresses in JavaScript encompasses the Regular Expression. As there exists no generic/ regular email...
  • Posted in: Tutorial » Javascript » | By: vaibhav gupta | Date: 20 Dec 2018 1:10 pm | Comments (0)
  • Ajax Interview Questions and Answers for Experienced
    What is Ajax & What does Ajax stand for? n nAJAX stands for Asynchronous JavaScript and XML. It is used to create better web applications using XHTML for developing the main content and CSS for...
  • Posted in: Articles » » | By: Jyoti Pandey | Date: 12 Feb 2019 8:53 am | Comments (0)
  • Smartforms Interview Questions and Answers
    SAP ABAP Smartforms Interview FAQ n nQ) Define Smart form? n nForm Printing in the Internet Age n nSmart Forms was initially presented in SAP Basis Release 4.6C primarily as a tool for the creation...
  • Posted in: Interview Questions » ABAP » | By: rekha | Date: 29 Jun 2018 1:19 pm | Comments (6)
    1.  Priniples of oops?2.  What is difference between procedural & OO Programming?3.  What is class?4.  What is object?5.  Can we instantiate a class within implementation...
  • Posted in: Interview Questions » ABAP » | By: vishal singh | Date: 18 May 2018 11:23 am | Comments (1)
  • BAPI Interview Questions and Answers
    General BAPI Interview Questions n n1) Define BAPI? n nBAPI is a standardized programming interface (method) which enable external applications to gain access to business processes and data in...
  • Posted in: SAP Blogs » » | By: rekha | Date: 08 Jan 2019 6:43 am | Comments (1)
  • Reorganizations Interview Question and Answers
    nFAQ: Reorganizations 1. What is reorganization?The term reorganization refers to the reconstruction of objects in the database. A distinction is made between offline and online...
  • Posted in: Interview Questions » Oracle » | By: rekha | Date: 19 May 2018 4:27 am | Comments (0)
  • ALV Layout Interview Questions
    [1] Question: What do the terms "display variant" and "layout" mean? n nAnswer: Both the term "display variant" and the term "layout" refer to the same thing...
  • Posted in: Interview Questions » ABAP » | By: rekha | Date: 18 May 2018 12:00 pm | Comments (0)
  • JMon Interview Questions and Answers
    FAQ: JMon1.Q: The JVM cores on Windows 2000 with the following error in the file hs_err_pidxxxx.log: An unexpected exception has been detected in native code outside the VM. Unexpected Signal:...
  • Posted in: Interview Questions » Java » | By: rekha | Date: 20 May 2018 1:51 am | Comments (1)
  • SAP EHS Interview Questions
    Hello SAP Experts, n nI Need SAP EHS interview questions and answers that are asked usually in any interivew. Please try to share them with me as soon as possible so that I can read and follow them...
  • Posted in: Forum » EHS ( Environment, Health, and Safety Management ) » | By: | Date: 18 May 2018 11:53 pm | Comments (1)
  • Order Management Interview Questions
    Hello Experts, n nI have recently faced an interview of a Company and the interviewer asked me these question which i have mentioned below: n nFirst question : If a xyz sales person(may be he meant...
  • Posted in: Forum » SD (Sales and Distribution) » | By: Rohit Mahajan | Date: 04 Dec 2018 7:21 am | Comments (4)
  • Authorizations Interview Question and Answers
    FAQ: General Questions About Authorizations[1] Question: Can wildcards be used in authorizations?[2] Question: What does the PFCG_TIME_DEPENDENCY clean up?[3] Question: What happens to change...
  • Posted in: Interview Questions » BASIS » | By: rekha | Date: 18 May 2018 12:09 pm | Comments (0)
  • MODULARIZATION Interview Questions and Answers
    MODULARIZATION FAQs1.Does every ABAP/4 have a modular structure?Yes.2.What is Modularization and its benefits?If the program contains the same or similar blocks of statements or it is required to...
  • Posted in: Interview Questions » ABAP » | By: Merityunjay Kumar Shukla | Date: 19 May 2018 11:07 am | Comments (1)
  • SDBI_CLUSTER_CHECK Interview Questions and Answers
    Q-1.Will I be able to run the SDBI_CLUSTER_CHECK without option "Find duplicates"? What is the impact?Ans) It is indeed possible to run the report without causing any impacts. The option...
  • Posted in: Interview Questions » NetWeaver » | By: vaibhav gupta | Date: 18 May 2018 3:51 pm | Comments (0)
  • Informatica Interview Questions and Answer
    Informatica FAQ's n n1. What is Enterprise Data Warehousing? n nA: Enterprise Data Warehousing is the creation of organization data at a single access point. Data with global view can be given to...
  • Posted in: SAP Blogs » » | By: Nitesh Singh | Date: 30 May 2018 11:08 am | Comments (0)
  • TestNG Interview Questions & Answers
    What is TestNG? n nTestNG is a tool to perform tasks like reporting, assertions, parallel test execution etc. integrating the framework with selenium or other automation tools. The NG in TestNG...
  • Posted in: Articles » » | By: Jyoti Pandey | Date: 15 Jan 2019 10:06 am | Comments (0)
  • SSRS Interview Questions and Answers
    What is SSRS? n nSQL Server Reporting Service is a server-based software system. It generates reports that Microsoft develops. You can prepare and deliver various printed reports that are...
  • Posted in: Articles » » | By: Shalesh Singh | Date: 11 Feb 2019 8:34 am | Comments (0)
  • VMware Interview Questions and Answers
    What is VMware? n nVMware is a software that enables you to do virtualization and cloud computing in your host computer. You can run a virtual computer from your own computer. The basis of...
  • Posted in: Articles » » | By: vaibhav gupta | Date: 24 Dec 2018 7:03 am | Comments (0)