Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, May 26, 2014

oDesk PHP4 Test Answers 2014

1. What is the result of the following expression:

5+2 * 4+6
a.  70
b.  19
c.  34
d.  21

2. What will be the output of following code?

$var1=”a”;
$$sar1=”b”;
echo “$var1 $a”;

a.   a b
b.   $var1 $a
c.   Error: $a is undefined
d.  Error: Parse error in line 2 ($$var1 = “b”)

3. Which of the following operators has the highst precedence?

a.  &
b.  %
c.  +
d.  &&
e.  +=

4. What will be the output of the following code?

$great = ‘fantastic’;
echo “This is {$great}”;

a.  Parse Error
b.  This is {fantastic}
c.  This is fantastic
d.  This is {$great}

5. Which of the following is not used for debugging PHP code?

a.  echo()
b.  checking the generated HTML code
c.  using the inbuilt debugger
d.  checking the error log file
6. What will happen with the following code segment?
$a = array( 1=> ‘one’, 2 => ‘two’, 3 = > ‘three’);
unset( $a[2] );

a.  $a[2] is ‘three’ and $a[3] is undefined
b.  $a[2] is ‘three’ and $a[3] is ‘three’
c.  $a[2] is undefined and $a[3] is ‘three’
d.  $a[2] is undefined and $a[3] is undefined

7. What will be the output of the following code?

$i=4;
$j=30;
$k=0;
$k=$j++/$i++;
echo $i . “ “ . $j . “ “ . $k . “ “ ;

a.  5 31 6
b.  5 31 6.2
c.  5 31 7
d.  4 31 7.5
e.  5 31 7.5

8. What will be the output of the following code?

$aa = 10;
echo ‘Value of a = $a’;

a.  Value of a = 10

b.  Value of a = $a
c.  Undefined
d.  Syntax Error

9. Which of the following operations has the lowest precedence?

a.  &
b.  %
c.  +
d.  &&
e.  +=

10. Which of the following regular expressions can be used to check for the validity of an e-mail address?

a.  ̂  [ ̂ @ ]+@ [ ̂ @ ]+\. [ ̂ @ ]+$
b.  ̂  [ ̂ @ ]+@ [ ̂ @ ]+ .[ ̂ @ ]+$
c.  $ [ ̂ @ ]+@ [ ̂ @ ]+\. [ ̂ @ ]+ ̂
d.  $ [ ̂ @ ]+@ [ ̂ @ ]+ .[ ̂ @ ]+ ̂

11. In PHP logical AND operator is represented by:

a.  &
b.  &&
c.  And
d.  .AND.

12. When the mail function returns the value true, it means:

a.  your email has reached in your outgoing mail service.
b.  your email has been forwarded successfully from your outgoing mail server.
c.  your email has reached the recipient’s mailbox (that’s not necessarily on their computer – it might be a holding mailbox at their ISP example).
d.  your outgoing mail server has rejected your request to relay the mail, as PHP isn’t an authorized user of that mail server.
e.  your email has reached the recipient and been read.

13. You need to keep track of how many objects of a given class exist WITHOUT introducing a non-class member variable. Which one of the following will allow you to do this?

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.”

14. Every switch-case statement must have a default block.

a.  true
b.  false

15. What will happen with the following code?

for ($i = 4; $i <= 6; print $i ++);

a.  it will print 455 as the output
b.  nothing will be printed at all cecause of a ; at the end of for statement
c.  cannot be determined because the code is incomplete
d.  Error: the for statement is not written properly

16. What will be the output of the following code?

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

a.  Value of a = 10
b.  Value of a = $a
c.  Undefined
d.  Syntax Error

17. Which of the following are not considered as Boolean false?

a.  FALSE
b.  0
c.  “0”
d.  “FALSE”
e.  4
f.  -4
g.  NULL

18. What will be the output of the following code?

class test
{
function set()
{
$a = 10;
}
function get()
{
return $a;
}
};
$t1 = new test;
$t1->set();
echo $t1->get();

a.  0
b.  10
c.  Error
d.  None of the above

19. What will be the output of the following code?

$str = < < <EOD
test line 1
test line 2
EDO;
echo $str;

a.  <<<EOD
b.  Syntax Error
c.  test line 1
     test line 2
d.  EOD

20. What will be the output of the following code?

echo 12 . 6;

a.  12 . 6
b.  126
c.  12.6
d.  Error: You cannot add integers through the concatenation operator(.)

21. Referrig to the sample code below, what will be the value of $z?

$x = 0xFFFE;
$y = 2;
$z = $x && $y;

a.  0
b.  1
c.  2
d.  3
e.  4

22. Consider the following two statements:

I – while (expr) statement
II – while (expr): statement  . . . endwhile;
Which of the followings are true?

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

23. 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

24. 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

25. To retain the value of a local variable of a function over multiple calls to that function, you must declare that variable as:

a.  local
b.  global
c.  static
d.  none of these

26. Which of the following functions can be used to timestamp a file?

a.  timestampfile
b.  file_time
c.  filectime
d.  time_stamp
e.  touch
f.  stampfile

27. If you are using sessions and use session_register() to register objects, these objects are serialized automatically at the end of each PHP page, and are unserialized automatically on each of the following pages.

a.  true
b.  false

28. Which of the following can be used to decrement the value of $var by 1?

a.  $var--;
b.  --$var;
c.  $--var;
d.  $var=-1;
e.  $var-=1;

29. Which of the following variable names are not correct?

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

30. Which of the following errors can a PHP compiler identify?

a.  syntax errors
b.  parse errors
c.  logical errors
d.  fatal errors

31. 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

32. 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

33. What will be the output of the following code?

echo 12.6;

a.  12.6
b.  126
c.  18
d.  Error: You cannot add integers through the concatenation operator(.)

34. In PHP, functions support:

a.  overloading
b.  setting default parameter values
c.  passing arguments by reference
d.  returning multiple values

35. Which of the following is an invalid operator in PHP 4.01?

a.  =
b.  +=
c.  ==
d.  +==
e.  ===

36. Referring to the sample code below, what will be the value of $z?

$x = 0xFFFE;
$y = 2 ;
$z = $x & $y;

a.  0
b.  1
c.  2
d.  3
e.  4

37. What is meant by the term variable functions?

a.  if a variable name has parenthesses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it
b.  if a variable name has parentheses appended to it, PHP will look for a function with the same name and will attempt to execute it
c.  There is no such term

38. Using In PHP?s stdClass feature you can create an object, and assign data to it, without having to formally define a class.

a.  true
b.  false

39. Which of the following is not used for variable-length argument lists in functions?

a.  func_num_args()
b.  func_var_args()
c.  func_get_arg()
d.  func_get_args()

40. Which of the following is an invalid mode for opening a file?

a.  r
b.  rw
c.  w
d.  a+
e.  b

oDesk PHP Test Answers 2014

Ques: The setrawcookie() method of setting cookies is different from PHP standard method of cookie setting as:
a. It does not allow expiry time to be set
b. It can be used only once
c. It does not URL-ENCODE the value on its own
d.It does not allow domain setting
Ans: C
Ques: You need to keep an eye on the existing number of objects of a given class without introducing a non-class varibale. which of the following makes this happen?
a. Add a member varibale that gets incremented in the default constructer and decremented the destructer.
b. Add a local variable that gets incremented in each constructer and decremented in the desructer
c. Add a static member variable that gets incremented in each constructer and decreented in the destructor
d. This cannot be accomplished since the creation of objects is being done dynamically via “new”
Ans: c
Ques: which of the following variable declaration within a class is invalid in PHP5?
a. private $type = “moderate”;
b. var $term = 3;
c. public $amn = “500″;
d. protected $name = ‘Quantes Private Limited’;
Ans: d
Ques: which of the following is not valid PHP parser tag?
a. script
b. ?p
c. %
d. ?php;
Ans: c
Ques: How can you hide the fact that web pages are written in PHP?
a. By using AddType application/X-httpd-php asp
b. Specify all file names without any dot and extension
c. By using .htaccess diretive in Apeche
d. All of the above
Ans: C
Ques: What is the output of the following code?
$a = 3;
$b = 2;
echo (int)$a/(int)$b
?>
a. 1
b. 1.5
c. 2
d. 3
e. Eroor
Ans: b

Ques: 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. non of the above
Ans: b
Ques: Which of the following set of operations is not valid in PHP 5?
a. >, >=
b. =,==
c. !==,!==
d. +=, *=
Ans: C
Ques: Late PHP version support remote file accessing for the functions:
a. include()
b. include_once()
c. require_once()
d. All of the above
Ans: D

Ques: 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
Ans: D
Ques: which of the following are used for code reuse?
a. Loops
b. functions
c. Database
d. include files
Ans: B,D
Ques: which of the following is the corect 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”) {………}
Ans: b
Ques: Which of the following are “magic constant”?
a. __LINE__
b. __FILE__
c __PRETTY_FUNCTION__
d __CLASS__
e. __METHOD__
Ans: c
Ques: 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)
Ans: a
Ques: Which one of the following is turnary operator?
a. &
b. =
c. :?
d. ?:
e. +=
f. &&
Ans: D
Ques: What is the result of the following Exprssion?
5+2*4+6
a. 70
b. 19
c. 34
d. 21
Ans: B
Ques: The default value of register global in PHP is:
a. Off
b. On
Ans: A
Ques: What would b the outpur of the following code?
$string = ‘good day’;
$string = ucword($string);
echo $string;
?>
a. good day
b. GOOD DAY
c. Good Day
d. non of the above
Ans: C
Ques: If you want to pass a value to a function by reference, the correct way is:
a. function ModifyReport(&$Rptfile){}
b. function ModifyReport($Rptfile){}
c. function ModifyReport(ByRef $Rptfile){}
d. function ModifyReport(&Rptfile){}
Ans: D

oDesk PHP 5 test answers 2014

Ques:     Which composite data types are supported by php?
Ans:     Array
Ques:     The default value of register_globals in PHP is:
Ans:     Off
Ques:     Which of the following is not a valid PHP connection status?
Ans:     open
Ques:     Choose the correct statement:
Ans:      include() includes and evaluates a specific file
require_once() includes and evaluates a specific file only if it has not been included before
Ques:     If the session_cache_expire() is not set, then by default the session cache will expire after:
Ans:     3 hrs
Ques:     What will be the output of the following script?
$count=50;
function Argument()
{
$count++;
echo $count;
}
Argument();
?>
Ans:     It will print 1
Ques:     What is true regarding this code?
Ans:     setcookie will return true
Ques:     Which of the following is not a correct way of printing text in php5?
Ans:     echo "Plain text";
Ques:     Which of the following is not the correct way of starting a session?
Ans:     session_initiate()
                                                                                                                      
Ques:     Which of the following functions do you need to implement HTTP Basic Authentication?
Ans:     None of the above
Ques:     Which of the following Command Line Interface constant is not defined in the CLI SAPI?
Ans:     STDPRT
Ques:     Which of the following statements is correct with regard to final and abstract?
Ans:     a. An abstract class cannot have final methods
Ques:     State whether True or False

Paamayim Nekudotayim operator allows access only to the static members of a class?
Ans:     True

Ques:     Which of the following statements is true with regard to comparisons in PHP5?
Ans:     With (===) operator, object variables are identical if and only if they refer to the same instance of the same class.

Ques:     Which of the following built-in function assist in checking if actually the function exists or not?
Ans:     function_exists
Ques:     What will be the output of the following code?
$a = 0.0;
for ($i = 0; $i < a ="="">
Ans:     1
Ques:     What will be the output of the following code?
$i=4;
$j=30;
$k=0;
$k=$j++/$i++;
echo $i . " " . $j . " " . $k . " ";
Ans:     5 31 7.5
Ques:     Which of the following is a not a correct way of commenting in php?
Ans:     /#PHP Comment
Ques:     Following is a php code block:
$m=9;
$n=99;
$z=8;
$z=$n++/$m++ + --$z;
echo $z;
what will be the output?
Ans:     18
Ques:     Which of the following is the correct way of specifying default value?
Ans:     function GetDiscount($Type = "Special") { . . . }
Ques:     With reference to the following php script:
print 'Text Line1'
print 'Text Line2'
?>
What will be the output on running the script?
Ans:     Error message will be printed
Ques:     What will be the ouput of the following code?
for ($i = 0; $i < i ="="">
0134
Ques:     Late PHP versions support remote file accessing for the functions:
Ans:     include_once()
          require_once()
both of them
Ques:     You have designed a user login form as follows:
User Name:  
Password:  
How can you access the username entered by the user in the 'Validate.php' webpage?
a. $var= $_POST['username'];
b. $var= $_REQUEST['username'];
c. import_request_variables('p', 'p_');
$var= $p_username;
Ans:      Both of them
Ques:     Which of the following does not represent logical AND operator in PHP?
Ans:     &amp
Ques:     Which of the following is not true for a persistent connection?
Ans:     These can't be converted to non-persistent connections
Ques:     Which of the following are invalid data types in PHP?
Ans:     char
Ques:     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?
Ans:     $ofc->getManager()->printName();
Ques:     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?
Ans:     public function getName(){}
Ques:     Which of the following variable declarations within a class is invalid in PHP5?
Ans:     var $term =3;
Ques:     What will be the output of following code?
$arr = "a";
$arr[0]="b";
echo $arr;
echo $arr[0];
Ans:     bb
Ques:     For the following code:
the output will be:
Ans:     171
Ques:     What is the result of the following expression?
Ans:     5+2 * 4+6
Ques:     What will be the output of following code?
$var = 1 + "-1.3e3";
echo $var;
Ans:     -1299
Ques:     What will be the output of following code?
$var1="a";
$$var1="b";
echo "$var1 $a";
Ans:     a b
Ques:    What is the output of the following code?
$a = 500;
$b = 200;
echo $a % 2
* $b;
?>
Ans:     0
Ques:     What will be the ouput of the following code?
if (-1)
print "true";
else
print "false";
?>
Ans:     true
Ques:     What will be the output of the following code?
echo 126;
Ans:     126
Ques:     Consider the following sample code:
$x = 0xFFFE;
$y = 2;
$z = $x && $y;
What will be the value of $z?
Ans:     1