28 Jan 2014

Odesk php 5 exam question and answer

Question: 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


Question:Which of the following variables is not related to file uploads?

a. max_file_size
b. max_execution_time
c. post_max_size
d. max_input_time

Question: You have a 2D array in PHP:

$array = array(array(141,151,161), 2,3, array(101, 202, 303));
You want to display all the values in the array The correct way is:

a.
function DisplayArray($array) {
   foreach ($array as $value) {
      if (array_valid($value)) {
         DisplayArray($value);
      } else {
         echo $value. “<br>”;
      }
   }
}

DisplayArray($array);
b.
function DisplayArray($array) {
   for ($array as $value) {
      if (valid_array($value)) {
         DisplayArray($value);
      } else {
         echo $value. “<br>”;
      }
   }
}

DisplayArray($array);
c.
function DisplayArray($array) {
   for ($array as $value) {
      if (is_array($value)) {
         DisplayArray($value);
      } else {
         echo $value. “&ltbr>”;
      }
   }
}

DisplayArray($array);
d.
function DisplayArray($array) {
   foreach ($array as $value) {
      if (is_array($value)) {
         DisplayArray($value);
      } else {
         echo $value “&ltbr>”;
      }
   }
}

DisplayArray($array);
Right answer: d.

Question: Multiple select/load is possible with:

a. Checkbox
b. Select
c. File
d. All of the above

Question: The following php variables are declared:

$company = ‘ABS Ltd’;
$$company =‘, Sydney’;
Which of the following is not a correct way of printing ‘ABS Ltd. Sydney’?

a. echo “$company $$company”;
b. echo “$company ${$company}”;
c. echo “$company ${‘ABS Ltd‘}“;
d. echo “$company {$$company}”;

Question (many answers)
We have two variable definitions:
1. 023
2. x23
Choose the correct options:

a. 1 is octal
b. 2 is hexadecimal
c. 2 is octal
d. 1 is hexadecimal

Question: Which of the following is a predefined constant?

a. TRUE
b. FALSE
c. NULL

e. CONSTANT

Question (many answers): Which of the following variable names are invalid?

a. $var_1
b. $var1
c. $var-1
d. $var/1
e. $vl

Question (many answers): Which of the following are not considered as boolean False?

a. FALSE
b. 0
c. “0”
d. “FALSE”
e. 1
f. NULL

Question: Which of the following regular expressions can be used to check the validity of an e-mail addresss?

a. ^[^@ ]+@[^@ ]+\.[“@ ]+$
b. ^[^@ ]+@[^@ ]+[^@ ]+$
c. $[^@ ]+@[^@ ]+\[^@ ]+^
d. $[^@ ]+@[^@ ]+[^@ ]+^

Question: Which of the following type cast is not correct?

$fig=23;
$varbl= (real) $fig;
$varb2 = (double) $flg;
$varb3 = (decimal) $flg;
$varb4 = (bool) $fig;

a. real
b. double
c. decimal
d. boolean

Question: 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

Question: 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.

Question: 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

Question: What will be the output of the following code?

$a = 10;
if($a > 5 OR < 15)
echo “true”;
else
echo “false”

a. true
b. false
c. No output
d. Parse Error

Question: 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

3 hrs by default.

Question: You need to check the size of a file in PHP function.

$size=X(filename);
Which function will suitably replace ‘X’ ?

a. filesize
b. size
c. sizeofFile
d. getSize

Question: 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

Question: Which of the following is a correct declaration?

a. static $varb = array(1 ,‘var, 3);
b. static $varb = 1+(2*9O);
c. static $varb = sqrt(81);
d. static $varb = new Object;

Question: You wrote following script to check for the right category:

<?php
$cate=5;
if ($cate==5)
{
?>
Correct category!
<?php
} else {
?>
Incorrect category!
<?php
}
?>

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

Question: If visibility is not defined for a method/member then it is treated as public static.

a. True
b. False

Question (many answers): 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 interlaces
c. An interlace can extend multiple interfaces
d. Methods with same name, arguments, and sequence can exist in the different interlaces implemented by a class

Question: Which of the following is a Ternary Operator?

a. &
b. =
c. : ?
d. ? :
e. +=
f. &&

Question: Which of the following are the valid PHP data types?

a. resource
b. null
c. boolean
d. string
e. Both a and c

g. All of the above 

Question: 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

Question: 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

Question: What will be the result of the following expression:

6+4 * 9-3

a. 60
b. 87
c. 39
d. 30

Question: Does php 5 support exceptions?

a. Yes
b. No

Question (many answers): Which of the following printing construct/function accepts multiple parameters?

a. echo
b. print
c. printf
d. Allof the above

Question: 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

Question: Which of the following is not true regarding XForms?

a. PHP provides support for XForm
b. It can be used on PDF documents
c. The data is sent in XML format
d. The action and method parameters are defined in the body

Question: How would you start a session?

a. session(start);
b. session();
c. session_start();
d. begin_sesion();

Question: How would you store order number (34) in an OrderCookie’?

a. setcookie(«OrderCookie”, 34);
b. makeCookie(”OrderCookie”, 34);
c. Cookie(«OrderCookie”, 34);
d. OrderCookie(34);

Question: What will be the output of the following code?

function fn(&$var) {
   $var = $var - ($var/l0*5);
   return $var;
)
echo fn(100);

a.100
b. 50
c. 98
d. Error message
e. None of the above

Question: What will be the result of following operation?

print 4 << 5;
a. 3
b. 128
c. 120
d. 6

Question: Which of the following is not supported in PHP5?

a. Type Hinting
b. Reflection
c. Magic Methods
d. Muftiple Inheritance
e. Object Cloning

Question: Which of the following is not a valid PHP parser tag?

b. ?p
c. %
d. ?php

Question: 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

Question: You need to keep an eye on the existing number of objects of a given class without introducing a non-class member variable.Which of the following makes this happen?

a. Add a member variable that gets incremented in the default constructor and decremented in the destructor
b. Add a local variable that gets incremented in each constructor and decremented in the destructor
c. Add a static member variable that gets incremented in each constructor and decremented in the destructor
d. This cannot be accomplished since the creation of objects is being done dynamically via “new”

Question: 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. Allof the above

Question: Which of the following is used to maintain the value of a variable over different pages?

a. static
b. global
c. session_register()
d. Noneoftheabove

Question: 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’;

Question: Consider the following two statements:

1 while (expr) statement
2 while (expr): statement endwhile;
Which of the following are true in context of the given statements?

a. 1 is correct and 2 is wrong

c. Both 1 & 2 are wrong
d. Both 1 & 2 are correct

Question: You have defined three variables $to, $subject, and $body to send an email. Which of the following methods would you use for sending an email?

a. mail($to,$subject,$body)
b. sendmail($to,$subject,$body)
c. mail(to,subject,body)
d. sendmail(to,subject,body)

Question: What is the output of the following code?
function vec_add (&Sa, Sb) {
   $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
[xJ =>12
[yJ => 5
[z] => -2
d. Error
e. None of the above

Question (many answers); Which of the the following are PHP file upload related functions?

a. upload_file()
b. is_uploaded_file()
c. move_uploaded_file()
d. Noneoftheabove

Question: Which of the following attribute is needed for file upload via form?

a. enctype=”multipart/formdata”
b. enctype=”singlepart/data’
c. enctype=»file”
d. enctype=»form-data/file”

Question: Variable/functions in PHP don’t work directly with:

a. echo()
b. isset()
c. print()
d. All of the above

Question: Which of the following is a PHP resource?

a. Domxml document
b. Odbc link

d. All of the above 

Question: The inbuilt function to get the number of parameters passed is:

a. arg_num()
b. func_args_count()
c. func_num_args()
d. None of the above

Question: 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();

Question: What will be the output of the following code?

echo 30 * 5.7

a. 150.7
b. 1507
c. 171
d. you can’t concatenate integers
e. error will occur

Question (many answers): 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 overloadedd. This produces a syntax error

Question: Which of the following pair have non-associative equal precedence?

a. +,-
b. ==,!=
C. «,»
d. &=,|=

Question: What does the array_combine (a, b) function do?

a. It appends b to a
b. It associates all keys of a with the values of b and returns a new array
c. It returns a new array with all values of b added to the values of a
d. It doesn't exist
e. None of the above

Question:  With what encoding does chr () work?

a. ASCII
b. UTF-8
c. UTF-16
d. Implementation dependent
e. None of the above

Question: Which of the following crypto in PHP returns longest hash value?

a. md5()
b. sha1()
c. crc32()
d. All return same length hash

Question: What is the output of the following code?

echo '1'.print(2) + 3;

a. 123
b. 321
c. 511
d. 155
e. 432

Question: Which of the following are useful for method overloading?

a. __call,__get,__set
b. _get,_set,_load
c. __get,__set,__load
d. __overload

Question: What will be the result of following operation?

print 4<< 5;

a. 3
b. 128
c. 120
d. 6

Question: What will be the result of the following expression:

6+4 * 9-3

a. 60
b. 87
c. 39
d. 30

Question: What is the output of the following code?

<?
echo 0500;
?>

a. 100
b. 500
c. 0500
d. 320
e. None of the above