Do you know that? 83% freelancers are paid after the agreed-upon date next

Contact Email: teammmrem@yahoo.com

<< All Upwork (oDesk) and Elance Tests << Elance test answers << IT & Programming category

Test answers for PHP 5 2020

(108, CL) Last updated: May 27
Elance • IT & Programming
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:



Collapse | Expand

108 Answered Test Questions:

1. Which subversion of PHP5 adds short array syntax?

Answers:

• 5

• 2

• 3

• 4

2. In mail($param1, $param2, $param3, $param4), the $param2 contains:

Answers:

• Time's Up!

• The subject

• The recipient

• The header

• The message

3. Name of the function to check the variable type is object

Answers:

• isObject

• is_object

• TypeOject

• (none of these)

4. What is the correct way to open the file "time.txt" as readable?

Answers:

• fopen("time.txt","r");

• fopen("time.txt","w+");

• open("time.txt");

• open("time.txt","read");

5. Does PHP5 support Exceptions?

Answers:

• No

• Yes

6. How would you start a session

Answers:

• session_start

• session(start)

• session

• begin_session

7. ( (4 >= 4 && 8 < 1) || (44 == 33 || 5 > 3) )  will return

Answers:

• TRUE

• FALSE

8. How can you enable the cURL extension?

Answers:

• You should insert the semicolon in the front of "curl_extension" in php.ini.

• None of these.

• You can use these functions without doing anything.

• You should remove the semicolon in the front of "curl_extension" in php.ini.

9. $x = 10.88; echo (int) $x;

Answers:

• 1

• 11

• 10

• 0

10. How can I identify the server IP address in PHP?

Answers:

• $_SERVER['SERVER_ADDR'];

• $_ADDRESS['server_ip'];

• server_id();

• server_addr();

11. The function used to iterate over array and object.

Answers:

• foreach

• while

• dowhile

• for

12. Which of the following function is used to check type of array

Answers:

• is_array

• isArray

• array_valid

• valid_array

13. (8 < 1 || 4 >= 4 ) will return

Answers:

• False

• True

14. $file = 'sample.txt'; $current = file_get_contents($file); $current .= "Additional Info"; file_put_contents($file, $current); What is the meaning of above code?

Answers:

• None of these

• It means that certain string of which value is 'Additional Info' is added to the end of the file named sample.txt.

• It means that certain string of which value is 'Additional Info' is over-written in the file named sample.txt.

15. True or false? One can include (??????abc.PHP??????) two times in a PHP page ??????makeit.PHP??????.

Answers:

• False

• True

16. What is the best way of writing an IF/ELSE statement on one line?

Answers:

• if ( $result ) echo "Win" else echo "Loss";

• if ( $result ) { echo "Win" } else { echo "Loss" };

• if ( $result ) { echo "Win"; } else { echo "Loss"; }

• echo ( $result ) ? "Win" : "Loss";

17. Which of the following is not a boolean false

Answers:

• False

• 1

• false

• (none of these)

18. Name of the function to check the variable type is object

Answers:

• TypeOject

• (none of these)

• isObject

• is_object

19. function foobar( ) {      $a = func_get_args( );     return $a[2]; } print foobar('a',1,'b',2);  What would the output be?

Answers:

• 1

• a

• 2

• b

• a2

20. True of false? PHP provides the goto in the latest version.

Answers:

• True

• False

21. What is the best way to URL encode a string?

Answers:

• urldecode( $str )

• urlencode( $str )

• urlcode( $str )

• encodeurl( $str )

• encode_url( $str )

22. Which of the following is not related to file

Answers:

• fappend

• fclose

• fopen

• fwrite

• fgets

23. $a = &$b; $b = 'Mary?'; print $a;

Answers:

• Mary?

• Fatal error

• Notice

• Warning

• Empty output

24. In mail($param1, $param2, $param3, $param4), the $param2 contains:

Answers:

• The message

• The recipient

• The subject

• The header

25. A fatal error would be caught by

Answers:

• E_ERROR

• ERROR

• E_WARNING

• E_ALERT

• E_NOTICE

26. Which of these functions will not result in a runtime error if the file requested does not exist or can't be opened?

Answers:

• require()

• include()

• nowarn()

• getFile()

27. How can we delete a file using php function.

Answers:

• drop

• remove

• unlink

• delete

• deletefile

28. Which of the following functions split the string and return the array?

Answers:

• strsplit()

• stringsplit()

• splitstr()

• str_split()

• split_str()

29. Which array function checks if the specified key exists in the array?

Answers:

• array_key_exists()

• array_search()

• isset()

• is_array()

30. Which values should be assigned to the variables $a, $b and $c in order for the following script to display the string Hello, World!   <?php  $string= "Hello, World!";  $a =?;  $b =?;  $c =?;  if($a) {      if($b &&!$c){          echo "Goodbye Cruel World!";      } else if(!$b &&!$c) {          echo "Nothing here";      }  } else {          if(!$b) {              if(!$a && (!$b && $c)) {                 echo"Hello, World!";             } else {                  echo"GoodbyeWorld!";              }         } else {          echo "Not quite.";      } }  ?>

Answers:

• True, True, True

• False, True, False

• False, True, True

• False, False, True

• True, True, False

31. How do you make PHP use a class file without having to require or include it manually?

Answers:

• Define __autoload($class) magic function

• Define $_MAP superglobal

• There's no way to do it

• Use set_class_handler($class_handler) function

• Set default_lib_path variable in php.ini

32. What is the difference between $message and $$message?

Answers:

• Memory pointer

• Error

• Classic example of PHP???s variable variables

33. What visibility level will this class property get in PHP5?  var $cool = true;

Answers:

• public

• private

• protected

• var keyword is no longer valid in PHP5

34. Which of the following is ternary operator

Answers:

• :?

• +=

• =

• &

• ?:

35. How do you connect mysql with the use of PHP5 new functions?

Answers:

• (both answers are correct)

• $connection = new mysqli('localhost', 'user', 'pass', 'test');

• $user = 'user'; $pass = 'pass'; $connection = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

36. Which of the following functions would one use to get the number of parameters passed?

Answers:

• func_get_args

• arg_num

• func_num_args

37. Which of the following is NOT supported in PHP5?

Answers:

• Magic Methods

• Object Cloning

• Type Hinting

• Multiple Inheritance

• Reflection

38. The ____ operator is used to test if two values are identical in every way.

Answers:

• ===

• !==

• ==

• instanceof

• =

39. $text = 'He went to the school.'; echo strpbrk($text, 'w');  In the above code, what is the output?

Answers:

• all of these

• true

• went to the school.

• 3

• None of these

40. $a = array("pomme", "banane"); $b = array(1 => "banane", "0" => "pomme");  var_dump($a == $b);  What does-it print ?

Answers:

• FALSE

• TRUE

41. What is the primary difference between a method declared as static and a normal method?

Answers:

• Static methods cannot be called from within class instances

• There is no functional difference between a static and non-static method

• Static methods don't have access to the self keyword

• Static methods do not provide a reference to $this

42. Which of the lines below will output the following string: "PHP is "super easy" to use!"

Answers:

• echo "PHP is "super easy" to use!";

• echo ("PHP is "super easy" to use!");

• echo (\"PHP is 'super easy' to use!\");

• echo "PHP is \"super easy\" to use!";

43. Which function would you use to append one or more elements to the end of the array?

Answers:

• array_unshift()

• array_push()

• array_pop()

• array_shift()

44. In PHP5 >= 5.3.0, which new operator was added?

Answers:

• GOTO

• &&

• ++

• --

• AND

45. What is PEAR in PHP?

Answers:

• There is no PEAR in PHP.

• PHP Extended Applications aRchive

• PHP Extension and Application Repository

46. Which of the following function is used to display the properties of variable?

Answers:

• var_dump

• none of the above

• define

• explain

47. How to open file in read/write mode?

Answers:

• $handle = fopen("http://www.example.com/", "r");

• $handle = fcopen("http://www.example.com/", "r+");

• $handle = fcopen("http://www.example.com/", "r");

• $handle = fileopen("http://www.example.com/", "r+");

• $handle = fopen("http://www.example.com/", "r+");

48. The PHP syntax is most similar to

Answers:

• Javascript

• VBScript

• Perl and C

49. Given: $email = ???bob@example.com???; which code block will output example.com?

Answers:

• print substr($email, -1 * strrpos($email, ???@???));

• print strstr($email, ???@???);

• print substr($email, strpos($email, ???@???) + 1);

• print substr($email, strrpos($email, ???@???));

50. Which of the following is a php resource?

Answers:

• (all of these)

• Database link

• File

• ODBC Link

51. Which of the following crpto return longest hash value

Answers:

• sha1()

• crc32()

• md5()

• All return same rate

52. Which of the following functions allows you to store session data in a database?

Answers:

• You cannot store session data in a database.

• mysql_query();

• session_set_save_handler();

• session_start();

53. Which function will list files and directories inside the specified path?

Answers:

• fscan()

• opendir()

• readdir()

• fopen()

• scandir()

54. Which of the following variable is not related to file upload

Answers:

• max_input_time

• post_max_size

• max_file_size

• max_execution_size

55. What is the difference between idate and date function?

Answers:

• All of these

• idate function always returns an integer, but date function returns formatted date string or FALSE.

• idate function always returns a formatted date string, but date function returns a formatted date string or FALSE.

• None of these

• idate function has more diverse expressions than date function.

56. Which function can be used to rename files?

Answers:

• die()

• fputs()

• copy()

• rename()

• fwrite()

57. $sweet = array('1' => 'apple', '2' => 'banana'); $fruits = array('delicious' => $sweet, 'sweet' => 'strawberry'); function myprint($item, $key) {     echo "$key is $item\n"; } array_walk_recursive($fruits, 'myprint');  In above code, what is the output?

Answers:

• [1 is apple] [2 is banana] [sweet is strawberry]

• [delicious is apple] [delicous is banana] [sweet is strawberry]

• [apple is delicious] [banana is delicious] [strawberry is sweet]

58. Include files must have the file extension ".inc"

Answers:

• No

• Yes

59. What is output of the following code. $arr = "a"; $arr[0]="b"; echo $arr; echo $arr[0];

Answers:

• Fatal Error.

• PHP Warning.

• ab

• aa

• bb

60. What is the correct way to include the file "time.inc" ?

Answers:

• <?php include file="time.inc"; ?>

• <?php include:"time.inc"; ?>

• <!-- include file="time.inc" -->

• <?php include "time.inc"; ?>

61. How do you kill or destroy a session?

Answers:

• destroy_session()

• session_kill()

• reset_session()

• session_destroy();

• kill_session()

62. To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.

Answers:

• array, interface

• access-list, instance

• instance, implements

• interface, implements

• interface, extends

63. How to check if a directory exists?

Answers:

• is_exists($name);

• file_exists($name);

• dir_exists($name);

• is_dir_exists($name);

64. What is the best way to iterate and modify every element of an array using PHP 5?

Answers:

• for($i = 0; $i < count($array); $i++) { /* ... */ }

• foreach($array as $key => $val) { /* ... */ }

• while(list($key, $val) = each($array)) { /* ... */}

• foreach($array as $key => &$val) { /* ... */ }

• You cannot modify an array during iteration

65. The contents of an image file are stored in memory as $imString, but the original file is not available. Of the following, which uses the least amount of code and is a valid method of retrieving the dimensions of $imString?

Answers:

• None of the above are valid PHP code

• $fn = tempnam('/dir', 'foobar'); file_put_contents($fn, $imString); return getimagesize($fn);

• $im = imagecreatefromstring($imString); return array(imagesx($im), imagesy($im));

• return strlen($imString);

• return getimagesizefromstring($imString);

66. Which of the following functions set options in curl script?

Answers:

• curl_set_opt()

• curl_opt()

• curl_set_option()

• curl_option()

• curl_setopt()

67. Which of the following functions compare the substrings of the parameters?

Answers:

• substr_compare()

• comp_substr()

• substr_comp()

• compare_substr()

• None of these

68. Which of the following is a correct declaration?

Answers:

• Static $var = new object;

• Static $var = array(10,'str',3);

• Static $var = 1+(5*13);

• Static $var = sqrt(25);

69. Which of following functions get a list of response headers sent (or ready to send)?

Answers:

• header_list()

• None of these

• headers_list()

• get_header_list()

70. How do you get header information from a URL?

Answers:

• get_header_info()

• get_headers()

• None of these

• get_header()

71. How should you filter variables before passing to header()?

Answers:

• strtr($var, "\r\n", ' ')

• PHP's doing this itself nowadays

• htmlspecialchars()

• urlencode()

72. Which variable type can NOT be used as a type hint?

Answers:

• callable

• any class name

• array

• resource

73. What is the output in following codes? <?php $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $result = array_intersect($array1, $array2); print_r($result); ?>

Answers:

• Array ( [a] => green [2] => red )

• Array ( [a] => green [1] => red )

• Array ( [a] => green [0] => red )

• Array ( [0] => green [1] => red )

• Array ( [a] => green [b] => red )

74. $a = array("pomme", "banane"); $b = array(1 => "banane", "0" => "pomme");  var_dump($a === $b);  What does-it print ?

Answers:

• TRUE

• FALSE

75. How do you instantiate a new object from class foo? class foo {     function do_foo()     {         echo "Doing foo.";      } }

Answers:

• $bar = construct foo;

• $bar = new foo;

• $bar = instantiate foo;

• $bar = construct foo();

• $bar = new foo();

76. <?php abstract class Animal {    function greeting() {      $sound = $this->sound();          return strtoupper($sound);    }      function sound();       }    class Dog extends Animal {    function sound() {                  return "Woof!";    }  }    $dog = new Dog();  echo $dog->greeting();   ?>

Answers:

• Fatal error

• Woof!

• Nothing

• All of the above

• WOOF!

77. What will the following script output? <?php $a = array (???a??? => 20, 1 => 36, 40); array_rand ($a); echo $a[0]; ?>

Answers:

• 20

• 36

• ???a???

• A random value from $a

• Nothing

78. echo new stdClass == new stdClass, '-', new stdClass !== new stdClass;

Answers:

• 1-0

• 0-1

• 1-1

• 0-0

79. Which function would you use to prepend one or more elements to the beginning of an array?

Answers:

• array_push()

• array_shift()

• array_pop()

• array_unshift()

80. What is the function to report errors from mysqli functions or queries?

Answers:

• mysqlireport();

• mysqli_report_error();

• mysql_generate_report();

• mysql_sql_exception

• mysqli_report();

81. $i = 5; print $i++ + ++$i;

Answers:

• Time's Up!

• 10

• 13

• 12

• 11

82. Which of the following functions is a relative ftp function new to PHP5?

Answers:

• ftp_chmod()

• ftp_chdir()

• ftp_read_write_alloc()

• ftp_alloc()

• ftp_mkdir()

83. What will be output of this code. function test(&$var) {     $var=$var-1;     return $var; } $returnVar = test(50); echo $returnVar. " is answer.";

Answers:

• Error message

• 50 is answer.

• 51 is answer.

• 49 is answer.

84. What will be the result of the following code ?  $a = 0 or 1; $b = 0 || 1; echo "$a, $b";

Answers:

• 1, 0

• 1, 1

• 0, 1

• 0, 0

85. The number of parameters in setCookie function

Answers:

• 7

• 2

• 5

• 3

• 4

86. What does php_strip_whitespace function return?

Answers:

• Returns the PHP source code in filename with PHP comments and whitespace removed.

• Returns the string with comments and whitespace removed.

• None of these

• Returns the PHP source code in filename with whitespace removed.

• Returns the string with whitespace removed

87. Which of following functions compute the intersection of arrays with additional index check and are defined newly in PHP5?

Answers:

• array_uintersect_assoc(); array_uintersect_uassoc();

• array_intersect_new_assoc(); array_intersect_new_uassoc();

• array_wintersect_assoc(); array_wintersect_uassoc();

• array_intersect_assoc(); array_intersect_uassoc();

• array_nintersect_assoc(); array_nintersect_uassoc();

88. $file = 'sample.txt'; $current = file_get_contents($file); $current .= "Additional Info"; file_put_contents($file, $current); What is the meaning of above code?

Answers:

• It means that certain string of which value is 'Additional Info' is over-written in the file named sample.txt.

• None of these

• It means that certain string of which value is 'Additional Info' is added to the end of the file named sample.txt.

89. How to open file in read/write mode?

Answers:

• $handle = fopen("http://www.example.com/", "r+");

• $handle = fileopen("http://www.example.com/", "r+");

• $handle = fopen("http://www.example.com/", "r");

• $handle = fcopen("http://www.example.com/", "r");

• $handle = fcopen("http://www.example.com/", "r+");

90. What is the correct way to include the file "time.inc" ?

Answers:

• <!-- include file="time.inc" -->

• <?php include file="time.inc"; ?>

• <?php include:"time.inc"; ?>

• <?php include "time.inc"; ?>

91. How can I identify the server IP address in PHP?

Answers:

• server_addr();

• $_ADDRESS['server_ip'];

• server_id();

• $_SERVER['SERVER_ADDR'];

92. What Does OOM mean?

Answers:

• Object Oriented Model

• Object Original Miscleneaous

• Object Over Masterclass

• Object Orientaton Mechnism

• Original Overlap Model

93. Which of the lines below will output the following string: "PHP is "super easy" to use!"

Answers:

• echo "PHP is \"super easy\" to use!";

• echo (\"PHP is 'super easy' to use!\");

• echo "PHP is "super easy" to use!";

• echo ("PHP is "super easy" to use!");

94. What function in PHP allows you to find the position of the first occurrence of a substring?

Answers:

• strripos()

• substr()

• strtok()

• str_repeat()

• strpos()

95. True or false? PHP provides the goto in the latest version.

Answers:

• True

• False

96. How do you make PHP use a class file without having to require or include it manually?

Answers:

• Define $_MAP superglobal

• Use set_class_handler($class_handler) function

• Set default_lib_path variable in php.ini

• Define __autoload($class) magic function

• There's no way to do it

97. In mail($param1, $param2, $param3, $param4), the $param2 contains:

Answers:

• The recipient

• The header

• The message

• The subject

98. What is the primary difference between a method declared as static and a normal method?

Answers:

• Static methods do not provide a reference to $this

• There is no functional difference between a static and non-static method

• Static methods don't have access to the self keyword

• Static methods cannot be called from within class instances

99. How do you connect mysql with the use of PHP5 new functions?

Answers:

• $user = 'user'; $pass = 'pass'; $connection = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

• (both answers are correct)

• $connection = new mysqli('localhost', 'user', 'pass', 'test');

100. Which of the following variables is not related to file upload?

Answers:

• post_max_size

• max_execution_size

• max_file_size

• max_input_time

101. What will be the output of the following code:  <?php class A {} class B {} class C extends B {}  class D {   function sayHello (A $argument) {     echo '$argument is an instance of A';   }    function sayHello (B $argument) {     echo '$argument is an instance of B';   } }  $d = new D(); $c = new C();  $d->sayHello($c);

Answers:

• $argument is an instance of B

• PHP Fatal error

• $argument is an instance of A

• Call to undefined method D::sayHello()

102. The contents of an image file are stored in memory as $imString, but the original file is not available. Of the following, which uses the least amount of code and is a valid method of retrieving the dimensions of $imString?

Answers:

• $fn = tempnam('/dir', 'foobar'); file_put_contents($fn, $imString); return getimagesize($fn);

• None of the above are valid PHP code

• return strlen($imString);

• $im = imagecreatefromstring($imString); return array(imagesx($im), imagesy($im));

• return getimagesizefromstring($imString);

103. How should you filter variables before passing to header()?

Answers:

• PHP's doing this itself nowadays

• strtr($var, "\r\n", ' ')

• urlencode()

• htmlspecialchars()

104. Which of the following is a correct declaration?

Answers:

• Static $var = new object;

• Static $var = 1+(5*13);

• Static $var = sqrt(25);

• Static $var = array(10,'str',3);

105. What result? $a = "1"; $a[$a] = "2"; echo $a;

Answers:

• 3

• error

• 1

• 12

• 2

106. $i = 5; print $i++ + ++$i;

Answers:

• 10

• 11

• 12

• 13

107. What will be the array $b after executing this code?  $a = array(1, 3, 5); $b = array(2, 4, 6); $b += $a;

Answers:

• $b = array(2, 4, 6)

• PHP Fatal Error

• $b = array(3, 7, 11)

• $b = array(2, 4, 6, 1, 3, 5)

• $b = array(1, 2, 3, 4, 5, 6)

108. For PHP version <= 5.3, how can we activate error reporting for all levels?

Answers:

• error_reporting(-1);

• error_reporting(0);

• error_reporting(E_ERROR);

• error_reporting(E_ALL);