Thursday 29 October 2015

PHP Interview Questions and Answers

PHP(Hypertext Preprocessor) most commonly asked Interview questions and answers are explain in simple language. PHP interview questions and answers are useful for both fresher’s and experience.
1. What is PHP?
PHP is acronym for Hypertext Preprocessor. It is open source web development scripting language. Servers are required for executing PHP scripts.
2. PHP Object Oriented or Procedure Oriented?
In PHP 5, many OOPS concepts were supported by PHP5, thus it is Object Oriented Language as well as Procedure Oriented Language. OOPS concepts are used along with procedure oriented features.
3. Write Hello World program using PHP?
Hello World program is used to print simple text, “Hello World”
<?php
echo “Hello World”;
?>
4. Why PHP is called as Loosely Type Language?
PHP is called has Loosely Typed Language because, in PHP we not declare variable data type (like integer, short, string etc.). PHP will automatically give best suited variable data type.
5. Does PHP syntax are similar with any programming language?
Yes, PHP Scripting language has similar syntax as of Java and Perl programming language.
6. Difference between GET and POST Method?
  • GET and POST both are used for sending information to server. Though there are many difference between GET and POST:
  • GET appends the value in the URL whereas POST does not append values in the URL
  • GET values are publicly available(because it values are appended in the URL) and POST is secure.
  • GET can send limited amount of data( because URL only supports 1024 characters) and POST can send any amount of information.
7. What are the types of errors in PHP?
The different types of PHP errors are: E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_USER_ERROR, E_USER_NOTICE, E_CORE_WARNING etc.
8. What are the different types of runtime errors in PHP?
There are mainly three types of runtime errors in PHP. They are Notices, Warnings and Fatal Errors. Notices are small errors which are not visible to users whereas warning are severe errors and it those errors are visible to users. Fatal errors are extremely severe errors which will stop PHP script execution.
9. Difference between Require and Include?
Require and Include statements are similar except during failure or errors. Require statement produces or results fatal error and it stops executing the script during failure whereas include statement does not stops scripts, just it shows warning.
10. What are the types of PHP Variables Scope?
PHP has three variable scope. They are: local, global and static. A local variable is declared inside the function whereas global variable is declared outside the functions. Local variable have access within the function only and global variable can be access from any function.
11. What are Array? How to create PHP Array?
Array can stores more than one variable. Arrays can store a list of similar items(like employee names, student details etc.) under single variable. Arrays in PHP can created using array() function.
12. What are the types of arrays in PHP?
There are three types of arrays in PHP. They are: Indexed Array, Associated Array and Multi-Dimensional Array.
13. Explain PHP Functions?
PHP functions are some block of code(which can be used for repetitive use or later in the program). PHP has both build-in functions and user-defined functions. PHP supports more than 1000+ built-in functions and user-defined functions are costumed functions.
14. What are conditional statements? Types?
Conditionals statements in PHP are used to perform certain action depending upon the given condition. Some of the conditional statement in PHP are: if, if..else, else….if and break statements.
15. Define PHP Filter?
PHP filters are used to obtain secure data, which is coming from users inputs like forms, cookie and other web services.
16. Explain PHP Session?
PHP sessions temporarily stores users data and information on web server to allow users to perform certain actions like adding shopping cart, sign in etc. Normal HTML pages does not support sessions, whenever a new page is loaded, all the data(information of users) will be lost. Thus PHP sessions overcomes it.
17. Explain PHP Cookie?
A Cookie is a small file, which is saved by server in users computer (downloaded through users browsers). Whenever the same user request webpage, the stored cookie is retrieved and returned to the server.
18. Does PHP supports inheritance?
Yes, PHP supports inheritance. Though, it does not supports multiple inheritance. Multiple inheritance can be used in PHP through interface.
19. Difference between print and echo in PHP?
  • In PHP, print and echo are basic output statements and there are almost similar. Though there are few difference between echo and print which are given below:
  • Print can take only one string(parameter) at a time while echo can take multiple string(parameter) at a time.
  • Print always returns 1 and echo does not have return value.
  • Echo is faster than print because echo does not return types
20. What are the exception handling in PHP?
In PHP, exception handling were in introduced in PHP 5. Whenever an error occurs during the execution of code, the exception handling change the flow of code to costumed exception. Exception Handling uses try, catch blocks.

No comments:

Post a Comment