Recently asked 15 PHP interview questions 2015 for freshers

In this section we are providing you some frequently asked PHP Interview Questions which will help you to win interview session easily. Candidates must read this section 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 codder. 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. Below are the Recently asked 15 PHP interview questions 2015 for freshers

Q. What is the difference between $name and $$name?

A. $name is variable where as $$name is reference variable like $name=ricky and $$name=negi so $ricky value is negi.

Q. What are the differences between Get and post methods?

A. There are some difference between GET and POST method
1. GET Method have some limit like only 2Kb data able to send for request But in POST method unlimited data can we send
2. when we use GET method requested data show in url but Not in POST method so POST method is good for send sensitive request

Q. What are the features and advantages of object-oriented programming?

A. One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns. For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system

Q. What are the differences between procedure-oriented languages and object-oriented languages?

A. There are lot of difference between procedure language and object oriented like below
1>Procedure language easy for new developer but complex to understand whole software as compare to object oriented model
2>In Procedure language it is difficult to use design pattern mvc , Singleton pattern etc but in OOP you we able to develop design pattern
3>IN OOP language we able to ree use code like Inheritance ,polymorphism etc but this type of thing not available in procedure language on that our Fonda use COPY and PASTE .

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

A. Three are three types of errors:
1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all although, as you will see, you can change this default behavior.
2. Warnings: These are more serious errors for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.

Q. What is difference between explode and implode in php

A. Explode() function divides a string into an array, but implode function() returns or combine a string from the elements of an array.
explode:

implode:

Output:
RissEnergyIndia

Q. What is the meaning of a final class and a final method?

A. ‘final’ is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overrided.

Q. How failures in execution are handled with include() and require() functions?

A. If the function require() cannot access to the file then it ends with a fatal error. However, the include() function gives a warning and the PHP script continues to execute.

Q.What is the main difference between require() and require_once()?

A.require() and require_once() perform the same task except that the second function checks if the PHP script is already included or not before executing it.

Q. What does the unset() function means?

A.The unset() function is dedicated for variable management. It will make a variable undefined.

Q How to initiate a session in PHP?

A The use of the function session_start() lets us activating a session.

Q How can we change the maximum size of the files to be uploaded?

A We can change the maximum size of files to be uploaded by changing upload_max_filesize in php.ini.

Q How to connect mysqli with php using Object-Oriented Way?

A. $host = “localhost”;
$username = “root”;
$password = “”;
$conn = new mysqli($host, $username, $password);
//connect to server
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
echo “Connected successfully”;

Q Give Curl example using post method?

A. $postData = array(
“site” => “web technology experts notes”,
“dailyuser” => “1000”,
“location” => “India”
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “http://www.example.com”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$output = curl_exec($ch);
curl_close($ch);
echo $output;

Q Difference between array_merge and array_combine in php?

A array_merge example

$array1 = array(‘one’,’two’);
$array2 = array(1,2);
$result = array_merge($array1,$array2);
print_r($result);

array_combine example

$array1 = array(‘one’,’two’);
$array2 = array(1,2);
$result = array_combine($array1,$array2);
print_r($result);