By: skill blog

Top 10 Questions And Answers for PHP Interview

Top 10 Questions And Answers for PHP Interview

php question answers



  1. What is PHP?

Ans.: PHP is an open source server-side scripting language commonly used in web applications.

  1. What is Open Source software?

Ans.: Software in which the source codes are freely used, modify, and shared by anyone is called Open Source software. These can also be distributed under licenses that adhere with the Open Source Definition.



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

Ans.: The include() statement includes and evaluates a specified line i.e. It will include a file based in the given path. require() does the same thing expect upon failure it will generate a fatal error and halt the scrip whereas include() will just gives a warning and allow script to continue. require_once() will check it the file already been included and if so it will not include the file again.

  1. What is the difference between GET, POST and REQUEST methods?

Ans.: GET and POST are used to send information from client browser to web server. In case of GET the information is send via GET method in name/value pair and is URL encoded. The default GET has a limit of 512 characters. The POST method transfers the information via HTTP headers. The POST method does not have any restriction in data size to be sent. POST is used for sending data securely and ASCII and binary type’s data. The $_REQUEST contains the content of bot $_GET, $_POST and $_COOKIE.

  1. Which are the different types of PHP?

Ans.: These are four types of errors.

  • Parse Error: Commonly caused due to syntax mistakes in codes. Ex. Missing semicolon, mismatch brackets.
  • Fatal Error: These are basically runtime errors which are caused when you try to access what can’t be done. Ex. Accessing a dead object, or trying to use a function that hasn’t been declared.
  • Warning Error: These occur when u try to include a file that is not present or delete a file that is not on the server. This will not halt the script; it will give the notice and continue with the next line of the script.
  • Notice Error: These errors occurs when u try to use a variable that hasn’t been declared, this will not halt the script, It will give the notice and continue with the next line of the script.




  1. What is the session and why do we use it?

Ans.: Session is a super global variable that preserves data across subsequent pages. Session uniquely defines each user with a session ID, so it helps to make customized web application where user tracking is needed.

  1. What is the cookie and why do we use it?

Ans.: Cookie is a small piece of information stored in the client browser. It is a technique used to identify a user using the information stored in their browser (it already visited that website). Using PHP we can both set and get COOKIE.

  1. How to print the current date and time?

Ans.: <?php

Echo date(‘Y-m-d H:i:s’);

?>

  1. What function do we use to find length of string, and length of array?

Ans.: For finding the length of string we use strlen() function and for array, we use count() function.

  1. What is the difference between unset() and unlink() function?

Ans.: unset() is used to destroy a variable whereas unlink() is used to destroy a file.



Leave a Reply

Your email address will not be published. Required fields are marked *