Below questions are the Odesk php 5 questions.I have given the answer of each question of the post Php 5 odesk testpapers. If.If you have anyother answer by logically please give that answer with logic in below the post “Php 5 odesk testpapers”.Sample test papers with answer for freelancer.PHP interview questions and answer for fresher and experienced. PHP practice papers.

Php 5 odesk testpapers. Sample test papers with answer for freelancer.PHP interview questions and answer for fresher and experienced. PHP practice papers.
odeskTestPapers


Question: You have two strings, which you want to concatenate.
$str1 = ‘Have a ‘;
$str2 = ‘Nice Day’;
The fastest way would be:

[plain]
a. $str1.Concat($str2);
b. $str1.$str2;
c. “$str1$str2”;
d. None of the above
[/plain]

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

[plain]
a. max_file_size
b. max_execution_time
c. post_max_size
d. max_input_time
[/plain]

Ans: b

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:

[plain]
a.
function DisplayArray($array) {
foreach ($array as $value) {
if (array_valid($value)) {
DisplayArray($value);
} else {
echo $value. “
“;
}
}
}

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

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

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

DisplayArray($array);
[/plain]
Right answer: d.

Question: Multiple select/load is possible with:

[plain]
a. Checkbox
b. Select
c. File
d. All of the above
[/plain]

Ans: b
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’?

[plain]
a. echo “$company $$company”;
b. echo “$company ${$company}”;
c. echo “$company ${‘ABS Ltd‘}“;
d. echo “$company {$$company}”;
[/plain]
Ans:a
Question (many answers)
We have two variable definitions:
1. 023
2. x23
Choose the correct options:

[plain]
a. 1 is octal
b. 2 is hexadecimal
c. 2 is octal
d. 1 is hexadecimal
[/plain]
Ans:a,b,d
Question: Which of the following is a predefined constant?

[plain]
a. TRUE
b. FALSE
c. NULL
e. CONSTANT
[/plain]

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

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

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

[plain]
a. FALSE
b. 0
c. “0”
d. “FALSE”
e. 1
f. NULL
[/plain]

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

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

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

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

[plain]
a. real
b. double
c. decimal
d. boolean
[/plain]

Ans: a
Question: Which of the following statements is not true with regard to abstract classes in php5?

[plain]
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
[/plain]

Ans: d
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;

[plain]
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.
[/plain]

Ans: d
Question: Which of the following characters are taken care of by htmlspecialchars?

[plain]
a. < b. >
c. single quote
d. double quote
e. &
f. All of the above
[/plain]

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

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

[plain]
a. true
b. false
c. No output
d. Parse Error
[/plain]

Ans: d
Question: If expire parameter of setCookie function is not specified then:

[plain]
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
[/plain]

Ans: b
Note: 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’ ?

[plain]
a. filesize
b. size
c. sizeofFile
d. getSize
[/plain]

Ans: a
Question: Which of the following text manipulation functions is supported by PHP?

[plain]
a. strtoupper()
b. ucfirst()
c. strtolower()
d. str_split()
e. All of the above
[/plain]

Ans: e
Question: Which of the following is a correct declaration?

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

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


Correct category!

Incorrect category!

What will be the output of the program if value of’cate’ remains 5?

[plain]
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
[/plain]

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

a. True
b. False

Ans: b
Question (many answers): Which of the following statements is incorrect with regard to interfaces?

[plain]

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
[/plain]

Ans: a,c,d
Question: Which of the following is a Ternary Operator?

[plain]
a. &
b. =
c. : ?
d. ? :
e. +=
f. &&
[/plain]

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

[plain]

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

g. All of the above
[/plain]

Ans: g
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


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

$Rent = 250;
function Expenses($Other) {
$Rent = 250 + $Other;
return $Rent;
}

Expenses(50),
echo $Rent;

[plain]
a. 300
b. 250
c. 200
d. Program will not compile
[/plain]

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

6+4 * 9-3

[plain]
a. 60
b. 87
c. 39
d. 30
[/plain]

Ans: 39
Question: Does php 5 support exceptions?

a. Yes
b. No


Ans: a

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

[plain]

a. echo
b. print
c. printf
d. Allof the above
[/plain]

Ans: a,c
Question: What will be the output of the following code?

$var = 10;
function fn() {
$var=20;
return $var;
}

Fn();
echo $var;

[plain]

a. 10
b. 20
c. Undefined Variable
d. Syntax Error
[/plain]

Ans: a

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

[plain]

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
[/plain]

Ans: a
Question: How would you start a session?

[plain]

a. session(start);
b. session();
c. session_start();
d. begin_sesion();
[/plain]

Ans: c

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

[plain]

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

Ans: a

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

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

[plain]
a.100
b. 50
c. 98
d. Error message
e. None of the above
[/plain]

Ans: d
Question: What will be the result of following operation?

print 4 << 5;
[plain]

a. 3
b. 128
c. 120
d. 6
[/plain]

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

[plain]

a. Type Hinting
b. Reflection
c. Magic Methods
d. Muftiple Inheritance
e. Object Cloning
[/plain]

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

[plain]

b. ?p
c. %
d. ?php
[/plain]

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

$a=10;
echo “Value of a =$a”;

[plain]

a. Value of a=10
b. Value of a=$a
c. Undefined
d. Syntax Error
[/plain]

Ans: a
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?

[plain]

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”
[/plain]

Ans: c
Question: Which of the following multithreaded servers allow PHP as a plug-in?

[plain]

a. Netscape FastTrack
b. Microsoft’s Internet Information Server
c. O’Reilly’s WebSite Pro
d. Allof the above
[/plain]

Ans: d

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

[plain]

a. static
b. global
c. session_register()
d. Noneoftheabove
[/plain]

Ans: c

Question: Which of the following variable declarations within a class is invalid in PHP5?

[plain]

a. private $type = ‘moderate’;
b. internal $term = 3;
c. public $amnt = ‘500’;
d. protected $name = ‘Quantas Private Limited’;
[/plain]

Ans: b

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?

[plain]

a. 1 is correct and 2 is wrong

c. Both 1 & 2 are wrong
d. Both 1 & 2 are correct
[/plain]

Ans: d

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?

[plain]

a. mail($to,$subject,$body)
b. sendmail($to,$subject,$body)
c. mail(to,subject,body)
d. sendmail(to,subject,body)
[/plain]

Ans: a

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);

[plain]

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
[/plain]

Ans: d

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

[plain]

a. upload_file()
b. is_uploaded_file()
c. move_uploaded_file()
d. Noneoftheabove
[/plain]

Ans: b,c

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

[plain]

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

Ans: a

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

[plain]

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

[/plain]

Ans: a

Question: Which of the following is a PHP resource?

[plain]

a. Domxml document
b. Odbc link

d. All of the above
[/plain]

Ans: d

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

[plain]

a. arg_num()
b. func_args_count()
c. func_num_args()
d. None of the above
[/plain]

Ans: c

Question: For the following code:

function Expenses() {
function Salary() {
function Loan() {
function Balance() {
}
}
}
}

Which of the following sequence will run successfully?

[plain]

a. Expenses();Salary();Loan; Balance();
b. Salary();Expenses();Loan(); Balance();
c. Expenses();Salary();Balance();Loan();
d. Balance();Loan();Salary(); Expenses();
[/plain]

Ans: a

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

echo 30 * 5.7

[plain]

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

Ans: c
Question (many answers): What is true regarding $a + $b where both of them are arrays?

[plain]

a. Duplicated keys are NOT overwritten
b. $b is appended to $a
c. The + operator is overloadedd. This produces a syntax error
[/plain]

Ans: a,b

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

[plain]

a. +,-
b. ==,!=
C. «,»
d. &=,|=
[/plain]

Ans: b

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

[plain]

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
[/plain]

Ans: b

Question: With what encoding does chr () work?

[plain]

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

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

[plain]

a. md5()
b. sha1()
c. crc32()
d. All return same length hash
[/plain]

Ans: a
Question: What is the output of the following code?

echo ‘1’.print(2) + 3;

[plain]

a. 123
b. 321
c. 511
d. 155
e. 432
[/plain]

Ans: 511

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

[plain]

a. __call,__get,__set
b. _get,_set,_load
c. __get,__set,__load
d. __overload
[/plain]

Ans: a

Question: What will be the result of following operation?

print 4<< 5;
[plain]

a. 3
b. 128
c. 120
d. 6
[/plain]

Ans: 128

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

6+4 * 9-3

[plain]

a. 60
b. 87
c. 39
d. 30
[/plain]

Ans: c

Question: What is the output of the following code?



[plain]

a. 100
b. 500
c. 0500
d. 320
e. None of the above
[/plain]



Ans: d

Php 5 odesk testpapers
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *