PHP Interview Questions and Answers – Fresher

php interview questions and answers freshers – I have discuss best PHP interview question and answers for fresher, which is very useful for even experienced PHP developers. I have add OOPS concept also because now most of the interviewer start the questions in OOPS concept so here I have share about it.
php interview questions and answers freshers

1.Tell something about PHP

PHP is an acronym for “PHP: Hypertext Preprocessor”. PHP is a server scripting language, use for develop dynamic web application. PHP scripts are executed on the server.

2.What is MVC?

MVC stands for Model, View, and Controller. PHP MVC is an effective way to manage the code into three different layers.

Model: Model represents the information in application.
View: View represents the visual representation of information and data that you have entered in the application.
Controller: Controller is actually how and in which way you wan to read the information in the application.

3.What are the difference types of CSS you can add in page?:

There are three types of CSS that can be added in a page.
1.External CSS
2.Internal CSS
3.Inline CSS

4.Does PHP supports multiple inheritances?

No, PHP supports only single level of inheritance. A class can be inherited from a single class using ‘extend’ keyword.

5.What is difference between echo and print>

Initially both look same because both used to display any value. Main difference between echo and print is that echo is just used to display any string in output. It will display whatever is passed to it but on other hand print is a function itself it not only display any value but also can return value.

6.What is difference between GET and POST method?

Whenever we fill any form on internet we can used one from two methods to send data on server computer, that method can be either GET or POST. When we use the GET method all information is displayed in address bar. If can sent upto 1024 of data using GET method so its good to use only when we are working with small scale application and data is not that much sensitive. If we talk about POST method, No information will be displayed on address bar and we can send upto 2mb of data using POST method. This limit can also extend further if required. PHP includes many CMS systems which can be used to handle the web content in effective way.

7.What functions are used to get the image size, Width and Height?

getimagesize () to get the size of an image.
Imagesx () to get width of an image
Imagesy () to get height of an image.

8.What is PEAR in PHP?

PEAR stands for “PHP Extension and Application Repository”. PEAR provides an inbuilt library of open source code for PHP developers. It provides support for package maintains and code distribution.

9.How do you upload videos using PHP & MySQL?

We just need to copy the path of stored videos in the database rather than storing the videos files itself. All videos will be saved
on a different folder and videos can be called from that folder when ever required. Default size is 2 mb for video files but we can change that size from max_file size option in php.ini file.

10.What are the different types of errors in PHP?

There are three types of errors encountered in PHP.

1. Notice: These are very normal and non-critical errors and they even not displayed to users. For examples accessing a variable that not existed at all.
2. Warning: These are little bit critical errors. These results are displayed to users but do not affect the output of code. For example trying to include any file that is not exists.
3. Fatal errors: These are really critical errors. For example calling any non existence class.

11.How constants are defined in a PHP script?

Define () is used to define constants in PHP.
define (“Newconstant”, 30);

12.How can we submit a form without using submit button?

We can use the hyper links to submit a form if we don’t want to use submit button. We have to use some java script code for that.

13.How to create an array of a group of items inside an HTML form ?

We can create input fields with same name for “name” attribute with squire bracket at the end of the name of the name attribute, It passes data as an array to PHP.

Object orientation is a software/Web development methodology that is based on the modeling a real world system.An object is the core concept involved in the object orientation. An object is the copy of the real world enity.An object oriented model is a collection of objects and its inter-relationships.

14.How do you define a constant?

Using define() directive, like define (“MYCONSTANT”,150)

15.How send email using php?

To send email using PHP, you use the mail() function.This mail() function accepts 5 parameters as follows (the last 2 are optional). You need webserver, you can’t send email from localhost. eg : mail($to,$subject,$message,$headers);

16.How to find current date and time?

The date() function provides you with a means of retrieving the current date and time, applying the format integer parameters indicated in your script to the timestamp provided or the current local time if no timestamp is given. In simplified terms, passing a time parameter is optional – if you don’t, the current timestamp will be used.

17.What is the maximum file size that can be uploaded in PHP and how can we increase it?

By default the maximum size of a file that can be uploaded is 2MB. you can change the maximum uploaded size value inside php.ini file set the value upload_max_filesize = 5M and restart all the services.

18.How can we increase the execution time of PHP ?

By default the maximum execution time of a PHP script is 30sec. If you want to change the following setup go inside php.ini file set max_execution_time = 40;

19.How can we get the value of current session id?

The session_id( ) function is used to get the current session id. It returns the session id for the current session.

20.How can we submit a html form without a submit button

The submit( ) function is used to submit form. first you have to get html form id through this document.getElementById(“formId”).submit() and then use submit( ) function. call this javascript function inside html body section at onclick=”your funciton name( )” events. set form action when you want to display the output, fetch the data on php and display your output.

21.What is the difference between session and cookie?

The main difference between session and cookies is that cookies are stored on the user’s computer in the text file format while sessions are stored on the server side.
Cookies can?t hold multiple variables on the other hand Session can hold multiple variables.You can manually set an expiry for a cookie, while session only remains active as long as browser is open.

22.What are the different loops in PHP?

For, while, do-while and for each.

23.How can you retrieve a cookie value?

echo $_COOKIE [“user”];

24.What is the use of header() function in PHP?

The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can’t print any HTML element before using this function.

25.What is the array in PHP?

Array is used to store multiple values in single value. In PHP, it orders maps of pairs of keys and values. It stores the collection of data type.

26.How can you submit a form without a submit button?

You can use JavaScript submit() function to submit the form without explicitly clicking any submit button.

27.What does isset() function?

The isset() function checks if the variable is defined and not null.

28.How to get the length of string?

The strlen() function is used to get the length of string.

29.How can you send email in PHP?

The mail() function is used to send email in PHP.
demo mail($to,$subject,$message,$header);

30.What is the difference between indexed and associative array?

The indexed array holds elements in an indexed form which is represented by number starting from 0 and incremented by 1. For example:
The associative array holds elements with name. For example:

31.What are the popular Content Management Systems (CMS) in PHP?

4.Drupal etc

32.What are the popular frameworks in PHP?

3.Yii 2
6.Zend Framework etc.

33.How to stop the execution of PHP script?

The exit() function is used to stop the execution of PHP script.

34.What is the use of count() function in PHP?

Count() function is used to count total elements in the array, or something an object.

35.Differentiate between require and include?

Require and include both are used to include a file, but if file is not found include sends warning whereas require sends Fatal error.

36.Explain the difference between PHP4 and PHP5.

PHP4 doesn’t support oops concept and uses Zend Engine 1.
PHP5 supports oops concept and uses Zend Engine 2.