• PHP Video Tutorials

PHP Mock Test



This section presents you various set of Mock Tests related to PHP. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

PHP Mock Test IV

Q 1 - Which of the following provides the error code associated with this file upload?

A - $_FILES['file']['error']

B - $_FILES['file']['name']

C - $_FILES['file']['size']

D - $_FILES['file']['type']

Answer : A

Explanation

$_FILES['file']['error'] − it provides the error code associated with this file upload.

Q 2 - Which of the following contains a reference to every variable which is currently available within the global scope of the script?

A - $GLOBALS

B - $_SERVER

C - $_COOKIE

D - $_SESSION

Answer : A

Explanation

$GLOBALS − Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables.

Q 3 - Which of the following is an array containing information such as headers, paths, and script locations?

A - $GLOBALS

B - $_SERVER

C - $_COOKIE

D - $_SESSION

Answer : B

Explanation

$_SERVER − This is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these. See next section for a complete list of all the SERVER variables.

Q 4 - Which of the following is an associative array of variables passed to the current script via HTTP cookies?

A - $GLOBALS

B - $_SERVER

C - $_COOKIE

D - $_SESSION

Answer : C

Explanation

$_COOKIE − An associative array of variables passed to the current script via HTTP cookies.

Q 5 - Which of the following is an associative array containing session variables available to the current script?

A - $GLOBALS

B - $_SERVER

C - $_COOKIE

D - $_SESSION

Answer : D

Explanation

$_SESSION − An associative array containing session variables available to the current script.

Q 6 - Which of the following gives a string containing PHP script file name in which it is called?

A - $_PHP_SELF

B - $php_errormsg

C - $_COOKIE

D - $_SESSION

Answer : A

Explanation

$_PHP_SELF − A string containing PHP script file name in which it is called.

Q 10 - Which of the following method of Exception class retrieve the error message when error occured?

A - getMessage()

B - getCode()

C - getFile()

D - getLine()

Answer : A

Explanation

getMessage() method of Exception class returns the message of exception.

Q 11 - Which of the following method of Exception class returns the code of exception when error occured?

A - getMessage()

B - getCode()

C - getFile()

D - getLine()

Answer : B

Explanation

getCode() method of Exception class returns the code of exception.

Q 12 - Which of the following method of Exception class returns source filename?

A - getMessage()

B - getCode()

C - getFile()

D - getLine()

Answer : C

Explanation

getFile() method of Exception class returns source filename.

Q 13 - Which of the following method of Exception class returns source line?

A - getMessage()

B - getCode()

C - getFile()

D - getLine()

Answer : D

Explanation

getLine() method of Exception class returns source line.

Q 14 - Which of the following method of Exception class returns array of the backtrace?

A - getMessage()

B - getCode()

C - getTrace()

D - getTraceAsString()

Answer : C

Explanation

getTrace() method of Exception class returns array of the backtrace.

Q 15 - Which of the following method of Exception class returns formated string of trace?

A - getMessage()

B - getCode()

C - getTrace()

D - getTraceAsString()

Answer : D

Explanation

getTraceAsString() method of Exception class returns formated string of trace.

Q 16 - Which of the following method returns current date and time?

A - time()

B - getdate()

C - date()

D - None of the above

Answer : A

Explanation

PHP's time() function gives you all the information that you need about the current date and time. It requires no arguments but returns an integer.

Q 17 - Which of the following method returns a formatted string representing a date?

A - time()

B - getdate()

C - date()

D - None of the above

Answer : C

Explanation

The date() function returns a formatted string representing a date. You can exercise an enormous amount of control over the format that date() returns with a string argument that you must pass to it.

Q 18 - Which of the following method connect a MySql database using PHP?

A - mysql_connect()

B - mysql_query()

C - mysql_close()

D - None of the above

Answer : A

Explanation

PHP provides mysql_connect function to open a database connection.

Q 19 - Which of the following method can be used to create a MySql database using PHP?

A - mysql_connect()

B - mysql_query()

C - mysql_close()

D - None of the above

Answer : B

Explanation

PHP uses mysql_query function to create a MySQL database.

Q 20 - Which of the following method can be used to close a MySql database using PHP?

A - mysql_connect()

B - mysql_query()

C - mysql_close()

D - None of the above

Answer : C

Explanation

PHP uses mysql_close function to close a MySQL database.

Q 21 - Which of the following method can be used to parse an XML document using PHP?

A - simplexml_load_string()

B - loadxml()

C - Both of the above.

D - None of the above.

Answer : C

Explanation

To create a SimpleXML object from an XML document stored in a string, pass the string to simplexml_load_string( ). It returns a SimpleXML object.

Q 22 - Can you create a class in PHP?

A - true

B - false

Answer : A

Explanation

Yes! class can be created in PHP.

Q 23 - Which of the following method acts as a constructor function in a PHP class?

A - class_name()

B - __construct

C - constructor

D - None of the above.

Answer : B

Explanation

PHP provides a special function called __construct() to define a constructor. You can pass as many as arguments you like into the constructor function.

Q 24 - Which of the following method acts as a destructor function in a PHP class?

A - class_name()

B - __destruct

C - destructor

D - None of the above.

Answer : B

Explanation

Like a constructor function you can define a destructor function using function __destruct(). You can release all the resourceses with-in a destructor.

Q 25 - final keyword prevents child classes from overriding a method by prefixing the definition with final?

A - true

B - false

Answer : A

Explanation

PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.

Answer Sheet

Question Number Answer Key
1 A
2 A
3 B
4 C
5 D
6 A
7 A
8 B
9 C
10 A
11 B
12 C
13 D
14 C
15 D
16 A
17 C
18 A
19 B
20 C
21 C
22 A
23 B
24 B
25 A
php_questions_answers.htm
Advertisements