Tuesday, May 21, 2013

oDesk PHP 5 Test Answers


Q1.Which of the following is not supported in PHP5?
a.     Type Hinting
b.     Reflection
c.     Magic Methods
d.     Multiple Inheritance
e.     Object Cloning
Q2.How would you start a session?
a.     session(start);
b.     session();
c.     session_start();
d.     begin_sesion();
Q3.What will be the result of the following expression:
6+4 * 9-3
a.     60
b.     87
c.     39
d.     30
Q4 . Which of the following attribute is needed for file upload via form?
a.  Enctype=”multipart/form-date”
b.  Enctype=”singlepart/date”
c.  Enctype=”file”
d.  Enctype=”form-data/file”
Q5 . The 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
d.     None of the above
Q6. Which of the following type cast is not correct?
$fig = 23;
$varbl = (real) $fig;
$varb2 = (double) $fig;
$varb3 = (decimal) $fig;
$varb4 = (bool) $fig;
?>
a.     real
b.     double
c.     decimal
d.     boolean
Q7 . 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
c.     Undefined
d.     Syntax Error
Q8. 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
Q9. Which of the following is not a file related function in PHP?
a.     fclose
b.     fopen
c.     fwrite
d.     fgets
e.     fappend
Q10.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
c.     Both are functions
d.     Both are constructs
Q11. 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;
Q12. Does PHP 5 support exceptions?
a.     Yes
b.     No
Q13.Which of the following is not a predefined constant?
a.     TRUE
b.     FALSE
c.     NULL
d.     __FILE__
e.     CONSTANT
Q14. Variable/functions in PHP don’t work directly with:
a.     echo()
b.     isset()
c.     print()
d.     All of the above
Q15. Which of the following is used to maintain the value of a variable over different pages?
a.     static
b.     global
c.     session_register()
d.     None of the above
Q16. 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
Q17. 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
c.     It can run on windows and Linux systems only
d.     It is compatible with most of the common servers used today
Q18. Does PHP provide the goto keyword in latest version?
a.     Yes
b.     No
Q19. What will be the result of following operation?
print 4<< 5;
a.     3
b.     128
c.     120
d.     6
Q20.You wrote following script to check for the right category
$cate=5;
if ($cate==5)
{
?>
Correct category!
} else {
?>
Incorrect category!
}
?>
What will be the output of the program if value of ‘cate’ remains 5?
a.     Correct category!
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
Q21. 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);
d.     count($HTTP_POST_PARAM);
Q22. If expire parameter of setCookie function is not specified then:
a.     Cookie will never expire.
b.     Cookie will expire with closure of the browser
c.     Cookie will expire with within 30 minutes
d.     Cookie will expire in 24 hours
Q23. 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’;
Q24. 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
Q25. Multiple select/load is possible with:
a.     Checkbox
b.     Select
c.     File
d.     All of the above
Q26.Which of the following variable names are invalid?
a.     $var_1
b.     $var1
c.     $var-1
d.     $var/1
e.     $v1
Q27. Which of the following are useful for method overloading?
a.     __call,__get,__set
b.     _get,_set,_load
c.     __get,__set,__load
d.     __overload
Q28. 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
Q29. 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
Q30. 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
Q31. 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
d.     Program will not compile
Q32. Which of the following pair have non-associative equal precedence?
a.     +, -
b.     ==, !=
c.     <<, >>
d.     &=, |=
Q33. 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
Q34. 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();
c.     Expenses();Salary();Balance();Loan();
d.     Balance();Loan();Salary();Expenses();
Q35.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.
d.     All will be printed on one line irrespective of the \n.
Q36. What is true regarding $a + $b where both of them are arrays?
a.     Duplicated keys are NOT overwritten
b.     $b is appended to $a
c.     The + operator is overloaded
d.     This produces a syntax error
Q37. Which of the following characters are taken care of by htmlspecialchars?
a.     <
b.     >
c.     single quote
d.     double quote
e.     &
f.     All of the above
Q38. 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
c.     Both I & II are wrong
d.     Both I & II are correct
Q39. 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
b.     False
Q40. What is the result of the following expression?
5+2*4+6
a.      70
b.      19
c.      34
d.      21
Q41.You need to heck the size of a file in php function .
$size=X(filename);
which function will suitable replace “X”?
a.      Filesize
b.      Size
c.      sizeofFile
d.     getSize
Q42.Which of the following is not true for a persistent connection?
a.    these are not closed even after the execution of the script
b.    these are mainly used to increase the efficiency of the system
c.    These can’t be converted to non-persistent connections
d.    These are preferable not used in the scripts involving transactions
Q43.Which one is correct?
a.     $s=fwrite(“a string here”);
b.    $s=fwrite($fp,”a string here”);
c.    $s=fwrite(“a string here ”,$fp);
d.    none of the above
Q44.Which of the following is not the correct way of starting a session?
a. session.auto_start
b. session_register()
c. session_initiate()
d. session_start()
Q45.Which of the following functions do you need to implement HTTP Basic Authentication?
a. authenticate ()
b. header ()
c. basic_auth ()
d. None of the above
Q46.Which of the following Command Line Interface constant is not defined in the CLI SAPI?
a. STDIN
b. STDOUT
c. STDPRT
d. STDERR
Q47.Which of the following statements is correct with regard to final and abstract?
a. An abstract class cannot have final methods
b. An abstract class cannot have non abstract methods
c. A final class cannot have abstract methods
d. A final class cannot have final methods
Q48.Which composite data types are supported by php?
a. Array
b. Enumeration
c. List
d. Object
e. Integer
Q49.Choose the correct statement?
a. include() includes and evaluates a specific file
b. require() includes and evaluates a specific file
c. include_once() includes and evaluates a specific file only if it has not been included before
d. require_once() includes and evaluates a specific file only if it has not been included before
e. All of the above
Q50.The default value of register_globals in PHP is?
a. Off
b. On
Q51.What will be the output of the following script?
$count=50;
function Argument()
{
$count++;
echo $count;
}
Argument();
?>
a. It will print 50
b. It will print 51
c. It will print 52
d. It will print 1
Q52.Which of the following is not a valid PHP connection status?
a. aborted
b. normal
c. open
d. timeout
Q53.State whether True or False?
Paamayim Nekudotayim operator allows access only to the static members of a class?
a. True
b. False
Q54.Which of the following built-in function assist in checking if actually the function exists or not?
a. exists
b. function_exists
c. fexists
d. isFunction
Q55.If the session_cache_expire() is not set, then by default the session cache will expire after?
a. 1 hr
b. 2 hrs
c. 3 hrs
d. 4 hrs
Q56.Which of the following does not represent logical AND operator in PHP?
a. &
b. &&
c. And
d. AND
Q57.What will be the output of the following code?
$a = 0.0;
for ($i = 0; $i < a =”=””>
a. 0.9
Not Equals
b. 1
Equals
c. 1
Not Equals
d. 1.1
Not Equals
e. None of the above
Q58.Which of the following is a not a correct way of commenting in php?
a. //PHP Comment
b. /*PHP Comment*/
c. #PHP Comment
d. /#PHP Comment
Q59.With reference to the following php script?
print ‘Text Line1′
print ‘Text Line2′
?>
What will be the output on running the script?
a. Text Line1Text Line2
b. Text Line1 Text Line2
c. ‘Text Line1′
d. ‘Text Line2′
e. Error message will be printed
Q60.Late PHP versions support remote file accessing for the functions?
a. include()
b. include_once()
c. require_once()
d. Both a and b
e. Both b and c
Q61.What will be the output of the following code?
echo 12 . 6;
a. 12 . 6
b. 126
c. 12.6
d. Error
Q62.Consider the following sample code:
$x = 0xFFFE;
$y = 2;
$z = $x && $y;
What will be the value of $z?
a. 0
b. 1
c. 2
d. 3
e. 4
Q63.Which of the following are invalid data types in PHP?
a. string
b. integer
c. float
d. char
e. array
f. object
Q64.Which of the following is the correct way of specifying default value?
a. function GetDiscount($Type = “Special”) { . . . }
b. function GetDiscount(Type := “Special”) { . . . }
c. function GetDiscount($Type := “Special”) { . . . }
d. function GetDiscount($Type : “Special”) { . . . }
Q65.What is the output of the following code?
$a = 500;
$b = 200;
echo $a % 2
* $b;
?>
a. 100
b. 200
c. 500
d. 0
e. Syntax error
Q66.What will be the output of following code?
$var = 1 + “-1.3e3″;
echo $var;
a. -1299
b. 1
c. 1-1.3e3
d. Error:cannot add integer and string
Q67.The classes are defined as follows:-
abstract class BaseCls{
protected abstract function getName();
}
class ChildCls extends BaseCls{
}
Which of the following implementations of getName() is invalid in ChildCls?
a. protected function getName(){}
b. function getName(){}
c. private function getName(){}
d. public function getName(){}
Q68.What will be the output of following code?
$var1=”a”;
$$var1=”b”;
echo “$var1 $a”;
a. a b
b. $var1 $a
c. Error: $a is undefined
d. Error: Parse error in line 2 ($$var1 = “b”)
Q69.Following is a php code block:-
$m=9;
$n=99;
$z=8;
$z=$n++/$m++ + –$z;
echo $z;
what will be the output?
a. 16
b. 18
c. 19
d. 20
e. 17
Q70.What will be the ouput of the following code?
if (-1)
print “true”;
else
print “false”;
?>
a. True
b. False
Q71.The Manager and Office classes are as follows:-
class Manager{
function printName() {
echo “Manager”;
}
}
class Office{
function getManager() {
return new Manager();
}
}
$ofc = new Office();
???
?>
Which of the following should replace ‘???’ to obtain the value of printName() function?
a. $ofc->getManager()->printName();
b. new Office()->getManager()->printName();
c. $ofc->getManager->printName;
d. Office::getManager()::printName();

No comments:

Post a Comment