php interview questions and answers

Posted by Unknown at 18:10

How echo()is differ than Print()in PHP?
Ans:
The main difference b/w echo() and Print() are given below:
1.echo() have support multiple arguments where as print() support only one argument.
2.Echo() doesn't have any return type.Where as Print() does return in terms of 0 or 1 for each success.So,that echo is faster than print because it does not returned any value.
3.echo is a statement Where Print is a function.
4.echo() first evaluate the string after that give output.
$i=6
echo "Value of i is $i"
output:
Value of i is 6
 print 'Value of i is $i'
output:
Value of i is $i


What do you understand about Magic Code in PHP?Ans:
In PHP we use some special type of character called Magic Code.Some magic codes are,
single quote( ' )
double quote( " )
amperson ( & )
We can escape magic code using slash(/).

Tell how we can run PHP in command line? Ans:
We can PHP in command line by using that:
php MyFileName.php

Can i convert PHP code into JAVA code?if yes,how? Ans:
Yes,We can convert PHP code into JAVA code.Like that:
echo "<script>JAVA code</script>"
 We can write PHP tags inside the javaScript tag.
<script language = javascript>
<?
     //code
  ?>
</script>

 What is the difference b/w isset and empty? Ans:
The main difference b/w isset and empty are given below:
isset: This variable is used to handle functions and checked a variable is set even through it is empty.
empty: This variable is used to handle functions and checked either variable has a value or it is an empty string,zero0 or not set at all.

What is the answer of following codeecho 1< 2 and echo 1 >2 ?
Ans:
Output of the given code are given below:
echo 1<2
output: 1
echo 1>2
output: no output

ReviewMe  What is the different b/w session and cookies in php? Ans:
The main difference b/n session and cookies in php are given below:
1.We store cookies in client machine and sessions in server machine.
2.Sessions are secured where as cookies are unsecured.
3.In cookies we stored limited amount of data,where as using session we can stored unlimited amount of data.
4.Session can store objects where cookies can store only strings.
5.Sessions work slower as compare to cookies.

What is the significance of destructor in PHP?
Ans:
In PHP their is an destructor function which is to be called when an object is deleted.We use destructor function ( _destruct() ).Which does have any parameters.
Example:
public function __destruct()
{
print "{$this->Name}\n";
}

How we use ceil() and floor() function in PHP?Ans:ceil() is use to find nearest maximum values of passing value.
Example:
$var=6.5;
$ans_var=ceil($var);
echo $ans_var;
Output:
7
floor() is use to find nearest minimum values of passing value.
Example:
$var=6.5
$ans_var=floor($var);
echo $ans_var;
Output:
6

How to distinguish b/n PHP and HTML?? Ans:Some main advantages between PHP and HTML are given below:
1.PHP is an server-side programing language where as HTML is an client-side programing language.
2.HTML is an static language where PHP is an dynamic language.Using PHP we can share files b/w webpages and accessing databases.
We have to still use HTML to work on PHP.

Output of the code? $objM = new M(); // Where, M is a class
$objN = $objM;
Ans:Both objM and objN are store same values.Because objM get the values from new M(); and it assign to the objN.So, we can say that both have contain same values.

How to get path of php.ini with a PHP script? Ans:
We use phpinfo(); to get path of php.ini with a PHP Script.

What do you understand about PHP accelerator ? Ans:Basically PHP accelerator is used to boost up the performance of PHP programing language.We use PHP accelerator to reduce the server load and also use to enhance the performance of PHP code near about 2-10 times.In one word we can say that PHP accelertator is code optimization technique.

What is the difference b/w unlink and unset ? Ans:The basic difference b/w unlink and unset is that, We use unlink function for file system handling.It will simply delete the file.Where unset is used to destroy the variable.

Which pre-defined classes in php ? Ans:Pre-defined classes that are in PHP are given below:
Standard Defined Classes
1. Directory
The class from which dir() is instantiated.
2. stdClass
Predefined classes as of PHP
1. php_user_filter
Special Classes
1. self
2. parent

How to encrypt the password in PHP? Ans:I have given you some examples that are used to encrypt the password in PHP:
Example:
1.Using md5() we can encrypt the password.
2.<?php
$password = crypt('ownpassword');
if(crypt($user_input, $password)==$password)
{
echo "Password checked!";
}
?>
 Above given both method only use to encrypt the password,Not used to decrypt password.

Write some array sort functions available in php ? Ans: I have given you eleven functions that are available in PHP for sorting an array:
1.asort()
2.arsort()
3.Ksort()
4.Krsort()
5.sort()
6.uasort()
7.uksort()
8.usort()
9.rsort()
10.natsort()
11.natcatsort()

What is the difference b/w $i and $$i? Ans:The main difference b/n $i and $$i is that $i is an variable where $$i is an reference variable.
Example:
$variable="welcome";
$welcome="abhi";
<?php
echo $variable;
echo $$variable;
?>
Output:
$variable=welcome;
$$variable=abhi;

 What is the difference b/w PHP4 and PHP5?Ans:The main difference b/w PHP4 and PHP5 are given below:
1.Generally,Both are same.PHP5 is a new version of PHP4.So,PHP5 has some improvement in design, security, and stability.
2.OOPS is used in PHP4 as well, with the difference that in PHP5 things are a little more evaluated.So, In PHP4 safety modes for classes (public, private) are not accepted.

What is the DDL,DCL and DML?Ans:DDL stands for Data Definition Language,DCL stands for Data Control Language and DML stands for Data Manipulation Language.We use DDL to Create,Alter or Drop the Data objects.We use DCL to do control over on Database transaction.In Oracle Grant and Revoke to control the transaction.We use DML to manipulate(Insert,Update,Delete) with the existing data in the database objects.

What is the substitution of submit in PHP?Ans:We can do that by using one these of methods:
1.By using JavaScript-formname.submit();
2.By using CURL functions
3.By using header
header("Location: page.php")

What is the difference b/n 'action' and 'target' in form tag?Ans:The main difference b/n 'action' and 'target' form tag.
 <form action="target"><input type="hidden" name="phpMyAdmin" value="f43d4e0b88acea2d2a393515f6bf38f2" /><input type="hidden" name="phpMyAdmin" value="70ac9566533a2665b6597346aab7f985" /> ..... </form>Where ACTION is an attribute.It is used to inform that from which place data has been come.data destination could be of an E-mail address.
Example:
action="mailto:abc@xyz.com";
Example:
action="c:/welcome.php"; It is an CGI script.
Example:
action="/cgi-sys/formmail.pl";
page that will process the data
Example:
action="search.asp",

What is .htaccessfile and how to use them? Ans:If we write an address in the address bar in our browser, system receives those files displayed on browser.Web server is use to controls which types of files are displayed.I have given you two most popular sides, these are IIS and Apache.
Syntax:
paths to files (directories) are specified from the server root.
domains with protocols specified.

What is Filter?How we use them?Ans:In PHP, We use Filters to validate and filter data coming from    insecure sources,like : user entered data.The main issue of introducing is that to make data filtering easier and quicker.Some filter function are given below:
1.filter_has_var � Checks if variable of specified type exists
2.filter_id � Returns the filter ID belonging to a named filter
3.filter_input_array � Gets external variables and optionally filters them
4.filter_input � Gets a specific external variable by name and optionally filters it
5.filter_list � Returns a list of all supported filters
6.filter_var_array � Gets multiple variables and optionally filters them
7.filter_var � Filters a variable with a specified filter

In PHP, We use Filters to validate and filter data coming from insecure sources,like : user entered data.The main issue of introducing is that to make data filtering easier and quicker.Some filter function are given below:1.filter_has_var � Checks if variable of specified type exists
2.filter_id � Returns the filter ID belonging to a named filter
3.filter_input_array � Gets external variables and optionally filters them
4.filter_input � Gets a specific external variable by name and optionally filters it
5.filter_list � Returns a list of all supported filters
6.filter_var_array � Gets multiple variables and optionally filters them
7.filter_var � Filters a variable with a specified filter

What do you understand about Exception Handling in PHP?Ans:In PHP 5 we introduce a Exception handle to handle run time exception.It is used to change the normal flow of the code execution if a specified error condition occurs.An exception can be thrown, and caught("catched") within PHP. Write code in try block,Each try must have at least one catch block. Multiple catch blocks can be used to catch different classes of exceptions. I have shown some error handler methods given below:
1.Basic use of Exceptions
2.Creating a custom exception handler
3.Multiple exceptions
4.Re-throwing an exception
5.Setting a top level exception handler

How we use Error logging error handling method in PHP?Ans:In PHP,by default an error log send to the error log system.By using error logging we can send and error log to the specific file.We checked this by using an example.In this we send a mail to our self with error message.And the scripts does not work when error comes.
Example:
<?php
//error handler function
function customError($errorno, $errorstr)
{
    echo "<b>Error:</b> [$errno] $errorstr<br />";
echo "program has been notified";
error_log("Error: [$errorno] $errorstr",1,
"abc@xyz.com","From: program@xyz.com");
}
//set error handler
set_error_handler("customError",E_USER_WARNING);
//trigger error
$i=0;
if ($i<=1)
{
trigger_error("I should be greater than 1", E_USER_WARNING);
}
?>
o/p:
[512] I should be greater than 1
program has been notified
Our mail have reply message like that,
Error: [512] I should be greater than 1

How we use Custom errors and error triggers error handling method in PHP?Ans:In Custom errors and error triggers,we handle errors by using self made functions.
1.Custom errors : By using this can handle the multiple errors that gives multiple message.
Syntax:
set_error_handler(\\\"Custom_Error\\\");
In this syntax if we want that our error handle, handle
only one error than we write only one argument otherwise
for handle multiple errors we can write multiple arguments.
Example:
<?php
//function made to handle errorfunction
custom_Error($errorno, $errorstr)
{
   echo \\\"<b>Error:</b> [$errorno] $errorstr\\\"; }
//set error handler like that
set_error_handler(\\\"custom_Error\\\");
//trigger to that error
echo($verify);?>
2.error trigger : In PHP we use error trigger to handle
those kind of error when user enter some input data.If
data has an error than handle by error trigger function.
Syntax:
<?php
$i=0;if ($i<=1)
{
trigger_error(\\\"I should be greater than 1 \\\");
}
?>
In this trigger_error function generate error when i is less than or greater than 1.

How we use Simple "die()" statements error handling method in PHP?Ans: I have given you a example.In this we try to open a file.
<?php
$file=fopen("R4R Welcome.txt","r");
?>
Suppose if that file does not exist,Than this type of message comes. fopen(R4R Welcome.txt) [function.fopen]: failed to open stream: No such file or directory in C:\PHP\Welcome.php on line 2
Now, we handle this error like that,
<?php
if(!file_exists("R4R Welcome.txt"))
{
die("File does not exist");
}
else
{
$file=fopen("R4R Welcome.txt","r");
}
?>
If file does not exist than output comes like that, File does not exist

How we handle errors in PHP?Explain it?Ans:In PHP we can handle errors easily.Because when error comes it gives error line with their respective line and send error message to the web browser.
When we creating any web application and scripts. We should handle errors wisely.Because when this not handle properly it can make bg hole in security.
In PHP we handle errors by using these methods:
1.Simple "die()" statements
2.Custom errors and error triggers
3.Error reporting

How we Sessions in PHP?Ans:We use session variable to store information or change setting about client session.A session variable is assign to the each client. Session has a particular working cycle like that 1.It create a unique id for each client
2.Store session variable according to client unique id.




If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

Blog Archive

 

© 2011. All Rights Reserved | Interview Questions | Template by Blogger Widgets

Home | About | Top