Wednesday, January 16, 2013

oDesk PHP5 Test 2012


Q.1: What will be the result of following operation? print 4<< 5;
a. 3
b. 128
c. 120 (Answer)
d. 6

Q.2: You wrote following script to check for the right category:
1 2 $cate=5;
3 …
4 …

6 if ($cate==5)
7 {
8 ?>
9 Correct category!
10 11 } else {
12 ?>
13 Incorrect category!
14 15 }
16 ?>
What will be the output of the program if value of ‘cate’ remains 5?
a. Correct category! (Answer)
b. Incorrect category!
c. Error due to use of invalid operator in line 6:”if ($cate==5)”
d. Error due to incorrect syntax at line 8, 10, 12 and 14

Q.3: You need to count the number of parameters given in the URL by a POST operation. The correct way is:
a. count($POST_VARS);
b. count($POST_VARS_PARAM);
c. count($_POST); (Answer)
d. count($HTTP_POST_PARAM);

Q.4: If expire parameter of setCookie function is not specified then:
a. Cookie will never expire.
b. Cookie will expire with closure of the browser (Answer)
c. Cookie will expire with within 30 minutes
d. Cookie will expire in 24 hours

Q.5: Which of the following variable declarations within a class is invalid in PHP5?
a. private $type = ‘moderate’;
b. internal $term =3;
c. public $amnt = ’500′;
d. protected $name = ‘Quantas Private Limited’; (Answer)

Q.6: Which of the following statements is not true with regard to abstract classes in php5?
a. Abstract classes are introduced in PHP5
b. A class with a single abstract method must be declared abstract
c. Abstract class can contain non abstract methods
d. Abstract method must have method definition and can have optional empty braces following it (Answer)

Q.7: Which of the following pair have non-associative equal precedence?
a. +, -
b. ==, !=
c. <<, >>
d. &=, |= (Answer)

Q.8: You have two strings, which you want to concatenate.
$str1 = ‘Have a ‘;
$str2 = ‘Nice Day’;
The fastest way would be:
a. $str1.Concat($str2);
b. $str1.$str2;
c. “$str1$str2″;
d. None of the above (Answer)

Q.9: For the following code:
function Expenses()
{
function Salary()
{
}
function Loan()
{
function Balance()
{
}
}
}
?>
Which of the following sequence will run successfully?
a. Expenses();Salary();Loan();Balance();
b. Salary();Expenses();Loan();Balance(); (Answer)
c. Expenses();Salary();Balance();Loan();
d. Balance();Loan();Salary();Expenses();

Q.10: Which of the following is not supported in PHP5?
a. Type Hinting
b. Reflection
c. Magic Methods
d. Multiple Inheritance (Answer)
e. Object Cloning

Q.11: How would you start a session?
a. session(start);
b. session();
c. session_start(); (Answer)
d. begin_sesion();

Q.12: What do you infer from the following code?
$str = ‘Dear Customer,\nThanks for your query. We will reply very soon.?\n Regards.\n Customer Service Agent’;
print $str;
?>
a. Only first \n character will be recognised and new line will be inserted.
b. Last \n will not be recognised and only first two parts will come in new lines.
c. All the \n will work and text will be printed on respective new lines. (Answer)
d. All will be printed on one line irrespective of the \n.

Q.13: What will be the result of the following expression: 6+4 * 9-3
a. 60
b. 87 (Answer)
c. 39
d. 30

Q.14: What is true regarding $a + $b where both of them are arrays?
a. Duplicated keys are NOT overwritten
b. $b is appended to $a (Answer)
c. The + operator is overloaded
d. This produces a syntax error
Q.15: Which of the following characters are taken care of by htmlspecialchars?
a. <
b. > (Answer)
c. single quote
d. double quote
e. &
f. All of the above

Q.16:nThe value of a local variable of a function has to be retained over multiple calls to that function. How should that variable be declared?
a. local
b. global
c. static (Answer)
d. None of the above

Q.17: Which of the following multithreaded servers allow PHP as a plug-in?
a. Netscape FastTrack
b. Microsoft’s Internet Information Server
c. O’Reilly’s WebSite Pro
d. All of the above (Answer)

Q.18: Multiple select/load is possible with:
a. Checkbox
b. Select
c. File
d. All of the above (Answer)

Q.19: Which of the following variable names are invalid?
a. $var_1
b. $var1 (Answer)
c. $var-1
d. $var/1
e. $v1

Q.20: Which of the following are useful for method overloading?
a. __call,__get,__set
b. _get,_set,_load
c. __get,__set,__load (Answer)
d. __overload

Q.21: What will be the output of the following code?
function fn(&$var)
{
$var = $var – ($var/10 * 5);
return $var;
}
echo fn(100);
a. 100
b. 50
c. 98
d. Error message
e. None of the above (Answer)

Q.22: Which of the following type cast is not correct?
1 2 $fig = 23;
3 $varbl = (real) $fig;
4 $varb2 = (double) $fig;
5 $varb3 = (decimal) $fig;
6 $varb4 = (bool) $fig;
7 ?>
a. real
b. double (Answer)
c. decimal
d. boolean

Q.23: What will be the output of following code?
$a = 10;
echo “Value of a = $a”;
a. Value of a = 10
b. Value of a = $a (Answer)
c. Undefined
d. Syntax Error

Q.24: What will be the output of the following code?
$var = 10;
function fn()
{
$var = 20;
return $var;
}
fn();
echo $var;
a. 10
b. 20
c. Undefined Variable
d. Syntax Error (Answer)

Q.25: Which of the following attribute is needed for file upload via form?
a. enctype=”multipart/form-data”
b. enctype=”singlepart/data” (Answer)
c. enctype=”file”
d. enctype=”form-data/file”

Q.26: Which of the following is not a file related function in PHP?
a. fclose
b. fopen
c. fwrite
d. fgets (Answer)
e. fappend

Q.27: Which of the following is correct with regard to echo and print ?
a. echo is a construct and print is a function
b. echo is a function and print is a construct (Answer)
c. Both are functions
d. Both are constructs

Q.28: Which of the following is a correct declaration?
a. static $varb = array(1,’val’,3);
b. static $varb = 1+(2*90);
c. static $varb = sqrt(81);
d. static $varb = new Object; (Answer)

Q.29: Consider the following two statements:
I while (expr) statement
II while (expr): statement … endwhile;
Which of the following are true in context of the given statements?
a. I is correct and II is wrong
b. I is wrong and II is correct (Answer)
c. Both I & II are wrong
d. Both I & II are correct

Q.30: You are using sessions and session_register() to register objects. These objects are serialized automatically at the end of each PHP page and are de-serialized automatically on each of the following pages. Is this true or false?
a. True (Answer)
b. False

Q.31: Which of the following text manipulation functions is supported by PHP?
a. strtoupper()
b. ucfirst()
c. strtolower()
d. str_split()
e. All of the above (Answer)

Q.32: Does PHP 5 support exceptions?
a. Yes (Answer)
b. No

Q.33: Which of the following is not a predefined constant?
a. TRUE
b. FALSE
c. NULL
d. __FILE__ (Answer)
e. CONSTANT

Q.34: Variable/functions in PHP don’t work directly with:
a. echo()
b. isset() (Answer)
c. print()
d. All of the above

Q.35: Which of the following is used to maintain the value of a variable over different pages?
a. static
b. global
c. session_register() (Answer)
d. None of the above

Q.36: Which of the following statements is incorrect with regard to interfaces?
a. A class can implement multiple interfaces
b. An abstract class cannot implement multiple interfaces
c. An interface can extend multiple interfaces
d. Methods with same name, arguments, and sequence can exist in the different interfaces implemented by a class (Answer)

Q.37: What is the output of the following code?
function
vec_add (&$a, $b)
{
$a['x'] += $b['x'];
$a['y'] += $b['y'];
$a['z'] += $b['z'];
}
$a = array (x => 3, y => 2, z => 5);
$b = array (x => 9, y => 3, z => -7);
vec_add (&$a, $b);
print_r ($a);
?>
a. Array
(
[x] => 9
[y] => 3
[z] => -7
)
b. Array
(
[x] => 3
[y] => 2
[z] => 5
)
c. Array
(
[x] => 12
[y] => 5
[z] => -2
)
d. Error
e. None of the above

Q.38: Which of the following statement is not correct for PHP?
a. It is a server side scripting language
b. A php file may contain text, html tags or scripts (Answer) 
c. It can run on windows and Linux systems only
d. It is compatible with most of the common servers used today

Q.39: Does PHP provide the goto keyword in latest version?
a. Yes
b. No (Answer)

Q.40: What will be the output of the following code?
$Rent = 250;
function Expenses($Other)
{
$Rent = 250 + $Other;
return $Rent;
}
Expenses(50);
echo $Rent;
a. 300
b. 250
c. 200 (Answer)
d. Program will not compile


powered by : infusion infotech

No comments:

Post a Comment