PHP Q B(2)
PHP Q B(2)
a) Rasmus Lerdorf
b) Willam Makepiece
c) Drek Kolkevi
d) List Barely
2. PHP files have a default file extension of..
a) .html
b) .xml
c) .php
d) .ph
3. A PHP script should start with ___ and end with ___:
a) < php >
b) < ? php ?>
c) <? ?>
d) <?php ?>
4. Which version of PHP introduced Try/catch Exception?
a)PHP 4
b)PHP 5
c)PHP 5.3
d)PHP 6
5. Which of the below symbols is a newline character?
a) \r
b) \n
c) /n
d) /r
6. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
a) 12
b) 1
c) Error
d) 5
7. Which of the below statements is equivalent to $add += $add ?
a) $add = $add
b) $add = $add +$add
C) $add = $add + 1
d) $add = $add + $add + 1
8. Which statement will output $x on the screen?
a) echo “\$x”;
b) echo “$$x”;
c) echo “/$x”;
d) echo “$x;”;
9. Which one of the following is the right way of defining a function in PHP?
a) function { function body }
b) data type functionName(parameters) { function body }
c) functionName(parameters) { function body }
d) function fumctionName(parameters) { function body }
10. A function in PHP which starts with __ (double underscore) is know as..
a) Magic Function
b) Inbuilt Function
c) Default Function
d) User Defined Function
11. Which one of the following PHP functions can be used to build a function that accepts any
number of arguments?
a) func_get_argv()
b) func_get_argc()
c) get_argv()
d) get_argc()
12. Which one of the following PHP functions can be used to find files?
a) glob()
b) file()
c) fold()
d) get_file()
13. Which of the following PHP functions can be used to get the current memory usage?
a) get_usage()
b) get_peak_usage()
c) get_memory_usage()
d) get_memory_peak_usage()
14. Which of the following PHP functions can be used for generating unique id’s?
a) uniqueid()
b) id()
c) md5()
d) mdid()
15. Which one of the following functions can be used to compress a string?
a) zip_compress()
b) zip()
c) compress()
d) gzcompress()
16. PHP’s numerically indexed array begin with position __.
a) 1
b) 2
c) 0
d) -1
17. Which function will return true if a variable is an array or false if it is not?
a) this_array()
b) is_array()
c) do_array()
d) in_array()
18. Which in-built function will add a value to the end of an array?
a) array_unshift()
b) into_array()
c) inend_array()
d) array_push()
19. Which function can be used to move the pointer to the previous array position?
a) last()
b) before()
c) prev()
d) previous()
20. Which function returns an array consisting of associative key/value pairs?
a) count()
b) array_count()
c) array_count_values()
d) count_values()
21. Which of the functions is used to sort an array in descending order?
a) sort()
b) asort()
c) rsort()
d) dsort()
22. Say in the above question you need to get the array sorted in the manner we humans would
have done it i.e picture1 then picture2 etc.. Which of the following function should be used?
a) dsort()
b) casesort()
c) natcasesort()
d) naturalsort()
23. The practice of separating the user from the true inner workings of an application through well-
known interfaces is known as..
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction
24. Which of the following term originates from the Greek language that means “having multiple
forms,” defines OOP’s ability to redefine, a class’s characteristics?
a) Abstraction
b) Polymorphism
c) Inheritance
d) Differential
25. The practice of creating objects based on predefined classes is often referred to as..
a) class creation
b) object creation
c) object instantiation
d) class instantiation
26. Which one of the following property scopes is not supported by PHP?
a) friendly
b) final
c) public
d) static
27. Which one of the following can be used to instantiate an object in PHP assuming class name to
be Foo?
a) $obj = new $foo;
b) $obj = new foo;
c) $obj = new foo ();
d) obj = new foo ();
28. Which one of the following is the right way to define a constant?
a) constant PI = “3.1415”;
b) const $PI = “3.1415”;
c) constant PI = ‘3.1415’;
d) const PI = ‘3.1415’;
29. Which one of the following is the right way to call a class constant, given that the class is
mathFunction?
a) echo PI;
b) echo mathFunction->PI;
c) echo mathFunction::PI;
d) echo mathFunction=PI;
30. Which one of the following is the right way to invoke a method?
a) $object->methodName();
b) object->methodName();
c) object::methodName();
d) $object::methodName();
31. Which method scope prevents a method from being overridden by a subclass?
a) Abstract
b) Protected
c) Final
d) Static
32. PHP recognizes constructors by the name..
a) classname()
b) _construct()
c) function _construct()
d) function __construct()
33. Which version of PHP introduced the instanceof keyword?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
34. Which one of the following functions is used to determine whether a class exists?
a) exist()
b) exist_class()
c) class_exist()
d) __exist()
35. Which one of the following functions is used to determine object type?
a) obj_type()
b) type()
c) is_a()
d) is_obj()
36. Which one of the following keyword is used to inherit our subclass into a superclass?
a) extends
b) implements
c) inherit
d) include
37. Which keyword is used to refer to properties or methods within the class itself?
a) private
b) public
c) protected
d) $this
38. Which keyword allows class members (methods and properties) to be used without needing to
instantiate a new instance of the class?
a) protected
b) final
c) static
d) private
39. Which version of PHP introduced the advanced concepts of OOP?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
40. Which one of the following is the right way to clone an object?
a) _clone(targetObject);
b) destinationObject = clone targetObject;
c) destinationObject = _clone(targetObject);
d) destinationObject = clone(targetObject);
41. If one intends to create a model that will be assumed by a number of closely related objects,
which class must be used?
a) Normal class
b) Static class
c) Abstract class
d) Interface
42. If your object must inherit behavior from a number of sources you must use a/an
a) Interface
b) Object
c) abstract class
d) static class
43. Which method is used to tweak an object’s cloning behavior?
a) clone()
b) __clone()
c) _clone
d) object_clone()
44. Which feature allows us to call more than one method or function of the class in single
instruction?
a) Typecasting
b) Method Including
c) Method adding
d) Method chaining
45. Which magic method is used to implement overloading in PHP?
a) __call
b) __invoke
c) __wakeup
d) __unset
46. How many error levels are available in PHP?
a) 14
b) 15
c) 16
d) 17
47. What is the description of Error level E_ERROR?
a) Fatal run-time error
b) Near-fatal error
c) Compile-time error
d) Fatal Compile-time error
48. Which version of PHP introduced E_STRICT Error level?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3
49. Which character do the error_reporting directive use to represent the logical operator NOT?
a) /
b) !
c) ~
d) ^
50. Say you want to report error concerned about fatal run-time, fatal compile-time error and core
error which statement would you use?
a) error_reporting = E_ALL
b) error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR
c) error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR
d) error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR
51. Which of the following statements causes PHP to disregard repeated error messages that occur
within the same file and on the same line?
a) ignore_repeated_errors
b) ignore_repeat_error
c) repeatedly_ignore_error
d) repeated_error_ignore
52. Which of the following is/are a PHP code editor?
i) Notepad
ii) Notepad++
iii) Adobe Dreamweaver
iv) PDT
a) Only iv)
b) All of the mentioned.
c) i), ii) and iii)
d) Only iii)
53. Which of the following must be installed on your computer so as to run PHP script?
i) Adobe Dreamweaver
ii) PHP
iii) Apache
iv) IIS
a) All of the mentioned.
b) Only ii)
c) ii) and iii)
d) ii), iii) and iv)
A) array_diff
B) diff_array
C) arrays_diff
D) diff_arrays
56. Which array function checks if the specified key exists in the array
(A) => array_key_exist()
(B) => array_key_exists()
(C) => array_keys_exists()
57. Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog()
functions?
a) define_variable()
b) define_log_variable()
c) log_variable()
d) define_syslog_variable()
58. Which logging option’s description is, if an error occurs when writing to the syslog, send output to
the system console?
a) LOG_CONS
b) LOG_NDELAY
c) LOG_ODELAY
d) LOG_PERROR
59. Which function is responsible for sending a custom message to the system log?
a) systemlog()
b) syslog()
c) log_system()
d) sys_log()
61. Which one of the following filter is used to filter several variables with the same or different
filters?
a) filter_var_array()
b) filter_var()
c) filter_input
d) filter_input_array
62. Which one of the following does not describe a validating filter?
a) Are used to allow or disallow specified characters in a string
b) Are used to validate user input
c) Strict format rules
d) Returns the expected type on success or FALSE on failure
63. Which one of the following filter checks if variable of specified type exists?
a) filter_has_var
b) filter_var
c) filter_id
d) filter_var_array
64. Which one of the following regular expression matches any string containing zero or one p?
a) p+
b) p*
c) P?
d) p#
66. How many functions does PHP offer for searching strings using POSIX style regular
expression?
a) 7
b) 8
c) 9
d) 10
71. Which one of the following function is capable of reading a file into an array?
a) file()
b) arrfile()
c) arr_file()
d) file_arr()
72. Which one of the following function is capable of reading a file into a string variable?
a) file_contents()
b) file_get_contents()
c) file_content()
d) file_get_content()
73. Which one of the following function is capable of reading a specific number of characters
form a file?
a) fgets()
b) fget()
c) fileget()
d) filegets()
74. Which one of the following function operates similarly to fgets(), except that it also strips
any HTML and PHP tags form the input?
a) fgetsh()
b) fgetsp()
c) fgetsa()
d) fgetss()
75. Which one of the following function outputs the contents of a string variable to the specified
resource?
a) filewrite()
b) fwrite()
c) filewrites()
d) fwrites()
A) preg_match
B) preg_search
C) preg_find
D) preg_found
77. Which one of the following preg PHP function is used to do a find and replace on a string or an
array?
a) preg_replace()
b) preg_find()
c) preg_find_replace()
d) preg_findre()
78. Which one of the following preg PHP functions is used to take a string, and put it in an array?
a) preg_destroy()
b) preg_split()
c) preg_unchain()
d) preg_divide()
80. Which one of the following databases has PHP supported almost since the beginning?
a) Oracle Database
b) SQL
c) SQL+
d) MySQL
81. The updated MySQL extension released with PHP 5 is typically referred to as..
a) MySQL
b) mysql
c) mysqli
d) mysqly
82. Which one of the following lines need to be uncommented or added in the php.ini file so as
to enable mysqli extension?
a) extension=php_mysqli.dll
b) extension=mysql.dll
c) extension=php_mysqli.dl
d) extension=mysqli.dl
83. I n which version of PHP was MySQL Native Driver(also known as mysqlnd) introduced?
a) PHP 5.0
b) PHP 5.1
c) PHP 5.2
d) PHP 5.3
84. Which one of the following statements is used to create a table?
a) CREATE TABLE table_name (column_name column_type);
b) CREATE table_name (column_type column_name);
c) CREATE table_name (column_name column_type);
d) CREATE TABLE table_name (column_type column_name);
85. Which one of the following statements instantiates the mysqli class?
a) mysqli = new mysqli()
b) $mysqli = new mysqli()
c) $mysqli->new.mysqli()
d) mysqli->new.mysqli()
86. Which one of the following statements can be used to select the database?
a) $mysqli=select_db(‘databasename’);
b) mysqli=select_db(‘databasename’);
c) mysqli->select_db(‘databasename’);
d) $mysqli->select_db(‘databasename’);
87. Which one of the following methods can be used to diagnose and display information about a
MySQL connection error?
a) connect_errno()
b) connect_error()
c) mysqli_connect_errno()
d) mysqli_connect_error()
88. Which method returns the error code generated from the execution of the last MySQL function?
a) errno()
b) errnumber()
c) errorno()
d) errornumber()
89. If there is no error, then what will the error() method return?
a) TRUE
b) FALSE
c) Empty String
d) 0
90. Which one of the following statements should be used to include a file?
a) #include ‘filename’;
b) include ‘filename’;
c) @include ‘filename’;
d) #include ;
91. Which one of the following methods is responsible for sending the query to the database?
a) query()
b) send_query()
c) sendquery()
d) query_send()
92. Which one of the following methods recuperates any memory consumed by a result set?
a) destroy()
b) remover()
c) alloc()
d) free()
93. Which of the methods are used to manage result sets using both associative and indexed arrays?
a) get_array() and get_row()
b) get_array() and get_column()
c) fetch_array() and fetch_row()
d) fetch_array() and fetch_column()
94. Which one of the following method is used to retrieve the number of rows affected by an INSERT,
UPDATE, or DELETE query?
a) num_rows()
b) affected_rows()
c) changed_rows()
d) new_rows()
96. Which of the following methods is used to execute the statement after the parameters have been
bound?
a) bind_param()
b) bind_result()
c) bound_param()
d) bound_result()
97. Which one of the following methods is used to recuperating prepared statements resources?
a) end()
b) finish()
c) final()
d) close()
98. Which method retrieves each row from the prepared statement result and assigns the fields to the
bound results?
a) get_row()
b) fetch_row()
c) fetch()
d) row()
101. Fill in the blank with the best option. An Object is a/an ___ of a class.
a) type
b) prototype
c) instance
d) object
103. Code that uses a class, function, or method is often described as the..
a) client code
b) user code
c) object code
d) class code
106. When you are building administrative links you’ll need to accept two arguments, which of the
following are they?
a) URL of previous entry and URL of the entry you are working with
b) The current page and previous page
c) URL of previous entry and previous page
d) The current page and URL of the entry you are working with
107. Once your application can generate administrative links, you need to load those links into ___.
a) php.ini
b) index.ini
c) index.php
d) start.php
108. The URLs in the administrative links won’t mean anything to admin.php unless you modify ___.
a) .htaccess
b) .adminaccess
c) .htmlaccess
d) .urlaccess
111. . Which one of the following keywords is used to define an abstract class?
a) extends
b) implements
c) abstract
d) new
112. Which one of the following is the correct abstract method?
a) public function write()
b) abstract function write()
c) abstract public write();
d) abstract public function write();
113. . Atleast how many abstract methods must an abstract class contain?
a) None
b) One
c) Two
d) Five
115. Which one of the following methods in the exception class, is used to get a nested exception
object?
a) getPrevious()
b) getCode()
c) getFile()
d) getLine()
116. Which one of the following keyword is used in conjunction with an Exception object?
a) throws
b) exception
c) throw
d) final
118. PHP provides built-in interceptor methods, which can intercept messages sent to undefined
methods and properties. This is also known as ___.
a) overloading
b) overriding
c) overbending
d) overbinding
119. Which one of the following method is invoked when a value is assigned to an undefined property?
a) __get()
b) __set()
c) __isset()
d) __call()
120. Which one of the following method is invoked when an undefined method is called by client code?
a) __get()
b) __isset()
c) __unset()
d) __call()
121. . Which method introduced in PHP 5, is invoked just before an object is garbage collected?
a) __collect()
b) __garbage()
c) __destruct()
d) __destructor()
122. Which keyword must be added before $first variable on the third line of the above question to
make $second and $first as distinct objects in PHP 5?
a) copy
b) clone
c) cut
d) Can’t add any word to make them distinct
125. Which directive determines whether PHP scripts on the server can accept file uploads?
a) file_uploads
b) file_upload
c) file_input
d) file_intake
126. Which of the following directive determines the maximum amount of time that a PHP script will
spend attempting to parse input before registering a fatal error?
a) max_take_time
b) max_intake_time
c) max_input_time
d) max_parse_time
128. Which superglobal stores a variety of information pertinent to a file uploaded to the server via a
PHP script?
a) $_FILE Array
b) $_FILEs Array
c) $_FILES_UPLOADED Array
d) $_FILE_UPLOADED Array
a. $get
b. $ask
c. $request
d. $post
134. When you need to obtain the ASCII value of a character which of the following
function you apply in PHP?
a. chr( );
b. asc( );
c. ord( );
d. val( );
135. Which of the following method sends input to a script via a URL?
a. Get
b. Post
c. Both
d. None
136. Which of the following function returns a text in title case from a variable?
A. ucwords($var)
B. upper($var)
C. toupper($var)
D. ucword($var)
137. Which of the following function returns the number of characters in a string
variable?
a. count($variable)
b. len($variable)
c. strcount($variable)
d. strlen($variable)
141. Which of the following php statement/statements will store 111 in variable num?
i) int $num = 111;
ii) int mum = 111;
iii) $num = 111;
iv) 111 = $num;
a) Both i) and ii)
b) All of the mentioned.
c) Only iii)
d) Only i)
143. Which of the following PHP statements will output Hello World on the screen?
i) echo (“Hello World”);
ii) print (“Hello World”);
iii) printf (“Hello World”);
iv) sprintf (“Hello World”);
a) i) and ii)
b) i), ii) and iii)
c) All of the mentioned
d) i), ii) and iv)
1. <?php
2. $a = "clue";
3. $a .= "get";
4. echo "$a";
5. ?>
a) get
b) true
c) false
d) clueget
1. <?php
2. $num = 10;
3. echo 'What is her age? \n She is $num years old';
4. ?>
146. Which of the following statements is/are true about Constructors in PHP?
i) PHP 4 introduced class constructors.
ii) Constructors can accept parameters.
iii) Constructors can call class methods or other functions.
iv) Class constructors can call on other constructors.
a) ii) and iii)
b) All of the mentioned
c) None of the mentioned
d) ii), iii) and iv)
147. Which of the following advanced OOP features is/are not supported by PHP?
i) Method overloading
ii) Multiple Inheritance
iii) Namespaces
iv) Object Cloning
a) All of the mentioned
b) None of the mentioned
c) i) and ii)
d) iii) and iv)
148. The class from which the child class inherits is called..
i) Child class
ii) Parent class
iii) Super class
iv) Base class
a) Only i)
b) ii), iii) and iv)
c) Only iii)
d) ii) and iv)
149. . If one intends to create a model that will be assumed by a number of closely related objects,
which class must be used?
a) Normal class
b) Static class
c) Abstract class
d) Interface
150. Which feature allows us to call more than one method or function of the class in single instruction?
a) Typecasting
b) Method Including
c) Method adding
d) Method chaining
152. . Which one of the following PHP functions can be used to find files?
a) glob()
b) file()
c) fold()
d) get_file()
153. Which function sets the file filename’s last-modified and last-accessed times?
a) sets()
b) set()
c) touch()
d) touched()
154. Which function is useful when you want to output the executed command’s result?
a) out_cmm()
b) out_system()
c) cmm()
d) system()
155. Which one of the following function reads a directory into an Array?
a) scandir()
b) readdir()
c) scandirectory()
d) readdirectory()
1. <?php
2. echo "chr(52)";
3. ?>
a) 1
b) 2
c) 3
d) 4
1. <?php
2. echo ord ("hi");
3. ?>
a) 106
b) 103
c) 104
d) 209
a) I love my country
b) i love my Country
c) I love my Country
d) I Love My Country
1. <?php
2. echo lcfirst("welcome to India");
3. ?>
a) welcome to India
b) welcome to india
c) Welcome to India
d) Welcome to india
161. How many functions does PHP offer for searching and modifying strings using Perl-
compatible regular expressions.
a) 7
b) 8
c) 9
d) 10
162. Say we have two compare two strings which of the following function/functions can you
use?
i) strcmp()
ii) strcasecmp()
iii) strspn()
iv) strcspn()
a) i) and ii)
b) iii) and iv)
c) None of the mentioned
d) All of the mentioned
163. Which one of the following functions will convert a string to all uppercase?
a) strtoupper()
b) uppercase()
c) str_uppercase()
d) struppercase()
1. <?php
2. echo str_pad("Salad", 5)." is good.";
3. ?>
a) SaladSaladSaladSaladSalad is good
b) is good SaladSaladSaladSaladSalad
c) is good Salad
d) Salad is good
165. Which one of the following functions can be used to concatenate array elements to form a
single delimited string?
a) explode()
b) implode()
c) concat()
d) concatenate()
166. Which one of the following functions finds the last occurrence of a string, returning its
numerical position?
a) strlastpos()
b) strpos()
c) strlast()
d) strrpos()
167. PHP has long supported two regular expression implementations known as ___ and ___.
i) Perl
ii) PEAR
iii) Pearl
iv) POSIX
a) i) and ii)
b) ii) and iv)
c) i) and iv)
d) ii) and iii)
168. Which one of the following regular expression matches any string containing zero or one p?
a) p+
b) p*
c) P?
d) p#
169. How many functions does PHP offer for searching strings using POSIX style regular
expression?
a) 7
b) 8
c) 9
d) 10
171. Which function will return true if a variable is an array or false if it is not?
a) this_array()
b) is_array()
c) do_array()
d) in_array()
172. Which two predefined variables are used to retrieve information from forms?
a) $GET & $SET
b) $_GET & $_SET
c) $__GET & $__SET
d) GET & SET
173. The attack which involves the insertion of malicious code into a page frequented by other
users is known as..
a) basic sql injection
b) advanced sql injection
c) cross-site scripting
d) scripting
174. When you use the $_GET variable to collect data, the data is visible to..
a) none
b) only you
c) everyone
d) selected few
175. Which variable is used to collect form data sent with both the GET and POST methods?
a)$BOTH
b)$_BOTH
c)$REQUEST
d)$_REQUEST
176. Which one of the following should not be used while sending passwords or other sensitive
information?
a) GET
b) POST
c) REQUEST
d) NEXT
177. Which function is used to remove all HTML tags from a string passed to a form?
a) remove_tags()
b) strip_tags()
c) tags_strip()
d) tags_remove()
178. To validate an e-mail address, which flag is to be passed to the function filter_var()?
a) FILTER_VALIDATE_EMAIL
b) FILTER_VALIDATE_MAIL
c) VALIDATE_EMAIL
d) VALIDATE_MAIL
179. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?
a) 5
b) 6
c) 7
d) 8
a. The message
b. The recipient
c. The header
d. The subject
a. database host
b. user ID
c. password
d. database name
a. sssion_decode
b. session_destroy
c. session_id
d. session_pw
a. </ />
b. <% %>
c. <? ?>
d. <script language="php"> </script>
186. Php supports all four different ways of delimiting. In this context identify the false
statement
a. echo ( )
b. print ( )
c. both
d. None
190. Which of the following function can assign the output to a string variable
a. echo ( )
b. print ( )
c. print f ( )
d. s print f ( )
191. Which of the following data type is not seal or datetype supported by PHP
a. Array
b. String
c. Float
d. Boolean
a. $ alive is false
b. $ alive is true
c. $ alive is overflow
d. the statement is snot valid