Php Interview Questions for Freshers

Php Interview Questions for Freshers:


Basic PHP Interview Questions as follows:

1. What is PHP?

Answer: PHP stands for Hypertext Preprocessor. It is an open-source, general-purpose, server side scripting language that is especially used for web development.

 2. What are some of the key features of PHP?

Answer: Some of the key features of PHP are: It is completely open-source. It is compatible with many databases, like MySQL, SQLite, etc. It is platform-independent, that is, it can be run on any operating system like Linux, Unix, Windows, etc. It is object-oriented, that is it supports object oriented functionalities like encapsulation, inheritance, abstraction, and polymorphism.

3. What are superglobals in PHP?

Answer: Superglobal variables in PHP are predefined global variables. Global variables are accessible from any part of a PHP script. Some examples of superglobal variables are $_GET, $_POST, $_REQUEST, $_FILES, $_COOKIE, $_SESSION, $_SERVER, $_ENV, and $GLOBALS. 

4. What are sessions and cookies in PHP? 

Answer: Sessions are global variables that are stored on the server inside the architecture. Every single session is tagged with a unique server ID that is later used to work with the storage and retrieval of values. It is stored server-side, that is, on the web server. It lasts for a shorter period of time, usually only until the user closes their browser. It can hold a large amount of data, usually 64mb or 128mb. Cookies are entities used to identify unique users in the architecture. It is a small file that the server plants into the client system. This is done to get useful information from the client for the development of various aspects of the server. It is stored on the user’s web browser. It lasts for a longer time, even after the user closes their browser. It can only hold a small amount of data, up to 4KB.

5. What are the different types of PHP errors?

Answer: There are three main types of errors in PHP. They are as follows: Notice: A notice is a non-critical error that is not displayed to the user. Warning: A warning is an error that is displayed to the user while the script is running. Fatal error: This is the most critical type of error. A fatal error will cause immediate termination of the script.

6. What are the rules for naming a PHP variable?

Answer: The following two rules are needed to be followed while naming a PHP variable: A variable must start with a dollar symbol, followed by the variable name. For example: $price=100; where price is a variable name. Variable names must begin with a letter or underscore. A variable name can consist of letters, numbers, or underscores. But you cannot use characters like + , – , % , & etc. A PHP variable name cannot contain spaces. PHP variables are case-sensitive. So $NAME and $name both are treated as different variables.

7. What are the different types of variables present in PHP?

Answer: There are 8 primary data types in PHP which are used to construct the variables. They are: Integers: Integers are whole numbers without a floating-point. Ex: 1253. Doubles: Doubles are floating-point numbers. Ex: 7.876 Booleans: It represents two logical states- true or false. NULL: NULL is a special type that only has one value, NULL. When no value is assigned to a variable, it can be assigned with NULL. Arrays: Array is a named and ordered collection of similar type of data. Ex: $colors = array("red", "yellow", "blue"); Strings: Strings are a sequence of characters. Ex: “Hello Er Shubham Sunny!” Resources: Resources are special variables that consist of references to resources external to PHP(such as database connections). Objects: An instance of classes containing data and functions. Ex: $mango = new Fruit();

8. What is the difference between “echo” and “print” in PHP?

Answer: The main difference between echo and print in PHP are given below: echo print echo can output one or more strings. print can only output one string and it always returns 1. echo is faster than print because it does not return any value. print is slower compared to echo. If you want to pass more than one parameter to echo, a parenthesis should be used. Use of parenthesis is not required with the argument list.

You Can check My YouTube Channel also:

Comments

Popular posts from this blog

Singleton in PHP

db socket in mysql