2015-11-23

1. Which subversion of PHP5 adds short array syntax?
Answers: • 4

2. In mail($param1, $param2, $param3, $param4), the $param2 contains:
Answers: • The subject

3. Name of the function to check the variable type is object
Answers: • is_object

4. What is the correct way to open the file "time.txt" as readable?
Answers: • fopen("time.txt","r");

5. Does PHP5 support Exceptions?
Answers: • Yes

6. How would you start a session
Answers: • session_start

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

8. How can you enable the cURL extension?
Answers: • You should remove the semicolon in the front of "curl_extension" in php.ini.

9. $x = 10.88; echo (int) $x;
Answers: • 10

10. How can I identify the server IP address in PHP?
Answers: • $_SERVER['SERVER_ADDR'];

11. The function used to iterate over array and object.
Answers: • foreach

12. Which of the following function is used to check type of array
Answers: • is_array

13. (8 < 1 || 4 >= 4 ) will return
Answers: • 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: • It means that certain string of which value is 'Additional Info' is added to the end of the file named sample.txt.

15. True or false? One can include (â?abc.PHPâ?) two times in a PHP page â??makeit.PHPâ?.
Answers: • True

16. What is the best way of writing an IF/ELSE statement on one line?
Answers: • echo ( $result ) ? "Win" : "Loss";

17. Which of the following is not a boolean false
Answers: • 1

18. Name of the function to check the variable type is object
Answers: • is_object

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

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

21. What is the best way to URL encode a string?
Answers: • urlencode( $str )

22. Which of the following is not related to file
Answers: • fappend

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

24. In mail($param1, $param2, $param3, $param4), the $param2 contains:
Answers: • The subject

25. A fatal error would be caught by
Answers: • E_ERROR

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: • include()

27. How can we delete a file using php function.
Answers: • unlink

28. Which of the following functions split the string and return the array?
Answers: • str_split()

29. Which array function checks if the specified key exists in the array?
Answers: • array_key_exists()

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: • False, False, True

31. How do you make PHP use a class file without having to require or include it manually?
Answers: • Define __autoload($class) magic function

32. What is the difference between $message and $$message?
Answers: • Classic example of PHP’s variable variables

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

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)

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

37. Which of the following is NOT supported in PHP5?
Answers: • Multiple Inheritance

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

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

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

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

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!";

43. Which function would you use to append one or more elements to the end of the array?
Answers: • array_push()

44. In PHP5 >= 5.3.0, which new operator was added?
Answers: • GOTO

45. What is PEAR in PHP?
Answers: • PHP Extension and Application Repository

46. Which of the following function is used to display the properties of variable?
Answers: • var_dump

47. How to open file in read/write mode?
Answers: • $handle = fopen("http://www.example.com/", "r+");

48. The PHP syntax is most similar to
Answers: • Perl and C

49. Given: $email = ‘bob@example.com’; which code block will output example.com?
Answers: • print substr($email, strpos($email, ‘@’) + 1);

50. Which of the following is a php resource?
Answers: • (all of these)

51. Which of the following crpto return longest hash value
Answers: • sha1()

52. Which of the following functions allows you to store session data in a database?
Answers: • session_set_save_handler();

53. Which function will list files and directories inside the specified path?
Answers: • scandir()

54. Which of the following variable is not related to file upload
Answers: • max_execution_size

55. What is the difference between idate and date function?
Answers: • idate function always returns an integer, but date function returns formatted date string or FALSE.

56. Which function can be used to rename files?
Answers: • rename()

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]

58. Include files must have the file extension ".inc"
Answers: • No

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

60. What is the correct way to include the file "time.inc" ?
Answers: • <?php include "time.inc"; ?>

61. How do you kill or destroy a session?
Answers: • session_destroy();

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: • interface, implements

63. How to check if a directory exists?
Answers: • file_exists($name);

64. What is the best way to iterate and modify every element of an array using PHP 5?
Answers: • foreach($array as $key => &$val) { /* ... */ }

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: • return getimagesizefromstring($imString);

66. Which of the following functions set options in curl script?
Answers: • curl_setopt()

67. Which of the following functions compare the substrings of the parameters?
Answers: • substr_compare()

68. Which of the following is a correct declaration?
Answers: • Static $var = array(10,'str',3);

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

70. How do you get header information from a URL?
Answers: • get_headers()

71. How should you filter variables before passing to header()?
Answers: • PHP's doing this itself nowadays

72. Which variable type can NOT be used as a type hint?
Answers: • 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 [0] => red )

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

75. How do you instantiate a new object from class foo? class foo { function do_foo() { echo "Doing foo."; } }
Answers: • $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

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

78. echo new stdClass == new stdClass, '-', new stdClass !== new stdClass;
Answers: • 1-1

79. Which function would you use to prepend one or more elements to the beginning of an array?
Answers: • array_unshift()

80. What is the function to report errors from mysqli functions or queries?
Answers: • mysqli_report();

81. $i = 5; print $i++ + ++$i;
Answers: • 12

82. Which of the following functions is a relative ftp function new to PHP5?
Answers: • ftp_alloc()

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

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

85. The number of parameters in setCookie function
Answers: • 7

86. What does php_strip_whitespace function return?
Answers: • Returns the PHP source code in filename with PHP comments and 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();

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

90. What is the correct way to include the file "time.inc" ?
Answers: • <?php include "time.inc"; ?>

91. How can I identify the server IP address in PHP?
Answers: • $_SERVER['SERVER_ADDR'];

92. What Does OOM mean?
Answers: • Object Oriented 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!";

94. What function in PHP allows you to find the position of the first occurrence of a substring?
Answers: • strpos()

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

96. How do you make PHP use a class file without having to require or include it manually?
Answers: • Define __autoload($class) magic function

97. In mail($param1, $param2, $param3, $param4), the $param2 contains:
Answers: • 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

99. How do you connect mysql with the use of PHP5 new functions?
Answers: • (both answers are correct)

100. Which of the following variables is not related to file upload?
Answers: • max_execution_size

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: • PHP Fatal error

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: • return getimagesizefromstring($imString);

103. How should you filter variables before passing to header()?
Answers: • PHP's doing this itself nowadays

104. Which of the following is a correct declaration?
Answers: • Static $var = array(10,'str',3);

105. What result? $a = "1"; $a[$a] = "2"; echo $a;
Answers: • 12

106. $i = 5; print $i++ + ++$i;
Answers: • 12

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)

108. For PHP version <= 5.3, how can we activate error reporting for all levels?
Answers: • error_reporting(-1);

Show more