PHP Interview Questions

We are providing some frequently asked PHP Interview Questions which will help you to win interview session easily. Candidates must read this section,Then by heart the questions and answers. Also, review sample answers and advice on how to answer these typical interview questions. PHP is an important part of the web world, and every web developer should have the basic knowledge in PHP. Common PHP interview questions, which should help you become a best PHP coder. We hope you find these questions useful. If you are an interviewer, Take the time to read the common interview questions you will most likely be asked.

Question-1. What is PHP ?

Answer- PHP is a recursive acronym for “PHP: Hypertext Pre-processor”. PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.

Question-2. What are the common usage of PHP ?

Answer- Common uses of PHP −

• PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
• PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data, return data to the user.
• You add, delete, and modify elements within your database through PHP.
• Access cookies variables and set cookies.
• Using PHP, you can restrict users to access some pages of your website.
• It can encrypt data.

 

Question-3. In how many ways you can embed PHP code in an HTML page ?

Answer- All PHP code must be included inside one of the three special mark-up tags ate are recognised by the PHP Parser.

  

 PHP code goes here 
Most common tag is the php

 

Question-4. What is the purpose of php.ini file ?

Answer- The PHP configuration file, php.ini, is the final and most immediate way to affect PHP’s functionality. The php.ini file is read each time PHP is initialized. In other words, whenever httpd is restarted for the module version or with each script execution for the CGI version. If your change isn’t showing up, remember to stop and restart httpd. If it still isn’t showing up, use phpinfo() to check the path to php.ini file

Question-5. What is escaping to PHP ?

Answer- The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as ‘escaping to PHP’.

Question-6. What do you mean by having PHP as whitespace insensitive ?

Answer- Whitespace is the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage returns (end-of-line characters). PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row. One whitespace character is the same as many such characters.

Question-7. Is PHP a case sensitive language ?

Answer- No, PHP is partially case sensitive.

Question-8. What are the characteristics of PHP variables ?

Answer- Here are the most important things to know about variables in PHP.

• All variables in PHP are denoted with a leading dollar sign ($).
• The value of a variable is the value of its most recent assignment.
• Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.
• Variables can, but do not need, to be declared before assignment.
• Variables in PHP do not have intrinsic types - a variable does not know in advance whether 
it will be used to store a number or a string of characters.
• Variables used before they are assigned have default values.
• PHP does a good job of automatically converting types from one to another when necessary.
• PHP variables are Perl-like.

 

Question-9. What are the different types of PHP variables ?

Answer- PHP has a total of eight data types which we use to construct our variables −

• Integers − are whole numbers, without a decimal point, like 4195.
• Doubles − are floating-point numbers, like 3.14159 or 49.1.
• Booleans − have only two possible values either true or false.
• NULL − is a special type that only has one value: NULL.
• Strings − are sequences of characters, like 'PHP supports string operations.'
• Arrays − are named and indexed collections of other values.
• Objects − are instances of programmer-defined classes, which can package up both other kinds of
 values and functions that are specific to the class.
• Resources − are special variables that hold references to resources external to PHP 
(such as database connections).

 

Question-10. What are rules for naming a PHP variable ?

Answer- Rules for naming a variable are following −

• Variable names must begin with a letter or underscore character.
• A variable name can consist of numbers, letters, underscores but you cannot use characters like 
+ , - , % , ( , ) . & , etc