MCQ Flashcards

1
Q

What will be the output of the following code?
<?php $x=; $y=20; echo $x;
?

>

A

Answer: a. Parse error: syntax error, unexpected ‘;’ in /opt/lampp/htdocs/er.php on line 3
Explanation: The code has a syntax error because $x is not assigned a value, leading to a parse error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Using _____ function it is possible to trigger an error anywhere in the program.

A

Answer: a. trigger_error()
Explanation: The trigger_error() function is specifically designed to trigger user-level errors in PHP.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

trigger_error() has at least _ number of parameters.

A

2
Explanation: The trigger_error() function requires at least two parameters: the error message and the error type (optional).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What will be the output of the following code?
<?php
function ($errno, $errstr) {
echo “Error:[$errno] $errstr”;

A

Parse error: syntax error, unexpected ‘set_error_handler’ (T_STRING) in /opt/lampp/htdocs/er.php on line 7
Explanation: The function definition is missing a name, which causes a parse error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What will be the output of the following code?
<?php
$x = 10;
$y = 20;
z = $x + $y;
echo $z;
?

?

A

Answer: a. Parse error: syntax error, unexpected ‘=’ in /opt/lampp/htdocs/er.php on line 5
Explanation: The variable $z is missing the dollar sign ($) before it, which causes a syntax error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Unexpected ‘{‘ is a Syntax Error.
a. True
b. False

A

Answer: a. True
Explanation: An unexpected { in PHP indicates that the parser encountered a curly brace where it did not expect one, which is indeed a syntax error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

try {
if($value == 9) {
throw new Exception(‘Number is 9 </br>’);
}
} catch(Exception $e) {
echo “</br>Exception Caught properly “, $e->getMessage();
} finally {
echo “This block clean all the activity “;

A

Exception Caught properly Number is 9 This block clean all the activity
Explanation: The exception is thrown and caught, displaying the message, followed by the finally block executing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

try {
if($value == 9) {
throw new Exception(‘Number is 9 </br>’);
}
} catch(Exception $e) {
echo “</br>Exception Caught properly “;
}
}
Test(99);
Test(9);

A

Exception Caught properly
Explanation: The first call to Test(99) does not throw an exception, so nothing is output. The second call to Test(9) throws an exception, but the catch block only outputs “Exception Caught properly”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

_____ It is a block of code where we can write code for which exception can occur.

A

try
Explanation: The try block is where you write code that may throw an exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

_____ block is used after the catch block

A

finally
Explanation: The finally block is executed after the try and catch blocks, regardless of whether an exception was thrown.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

_____ block is used to throw an exception.
a. try
b. catch
c. finally
d. None of the above

A

d. None of the above.
The throw statement is used to throw an exception, not a block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the following is an optional parameter?
a. host
b. dbname
c. username
d. socket

A

socket
Explanation: The socket parameter is optional when connecting to a MySQL database using MySQLi.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which of the following is not a parameter of mysqli_connect()? Options:
a. host
b. username
c. port
d. query

A

d. query
Explanation: The query is not a parameter of the mysqli_connect() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which of the following is correct syntax when the username and password are not set? Options:

a. $cn = new mysqli(“localhost”, “”, “”);
b. $cn = new mysqli(“localhost”, “NA”, “NA”);
c. $cn = new mysqli(“localhost”, “”, “”);
d. $cn = new mysqli(“localhost”, “ “, “ “);

A

Answer: a. $cn = new mysqli(“localhost”, “”, ““);
Explanation: This syntax correctly initializes a MySQLi connection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which of the following is not a method of the MySQLi extension? Options:
a. fetch_array()
b. fetch_row()
c. fetch_object()
d. fetch_data()

A

Answer: d. fetch_data()
Explanation: fetch_data() is not a method of the MySQLi extension. The correct methods are fetch_array(), fetch_row(), and fetch_object().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Is it possible to loop through MySQLi results? Options:
a. Yes
b. No
c. Cannot say

A

Answer: a. Yes
Explanation: It is possible to loop through MySQLi results using a loop structure, typically a while loop.

17
Q

Which of the following statement is used to loop through MySQLi results? Options:

a. if
b. while
c. switch
d. None of the above

A

Answer: b. while
Explanation: The while statement is commonly used to loop through MySQLi results.

18
Q

Which of the following method is used inside while loop to retrieve the data in rows from the database? Options:

a. mysqli_query()
b. fetch_data()
c. mysqli_fetch_array()
d. mysqli_debug()

A

Answer: c. mysqli_fetch_array()
Explanation: The mysqli_fetch_array() method is used to retrieve a result row as an associative array, a numeric array, or both.

19
Q

With the use of _____ statement can the user execute similar SQL statements repeatedly. Options:

a. prepare
b. view
c. stored procedure
d. template

A

Answer: a. prepare
Explanation: The prepare statement allows users to execute similar SQL statements repeatedly with different parameters.

20
Q

Which of the following are a type of argument of bind_param()?
i. s indicates string
ii. c indicates char
iii. i indicates integer
iv. b indicates BLOB
Options:
a. i, ii, iii
b. i, iii, iv
c. i, ii, iv
d. i, iii

A

Answer: b. i, iii, iv
Explanation: The bind_param() method uses i for integer, s for string, and b for BLOB. The c for char is not a valid type in this context.

21
Q

Prepare statement is not supported in MySQLi? Options:
a. Yes
b. No

A

Answer: b. No
Explanation: This statement is incorrect; prepared statements are indeed supported in MySQLi.

22
Q

Which of the following does not support the SQL queries with ? Options:
a. bind_result()
b. get_result()
c. store_result()
d. None Of the Above

A

Answer: a. bind_result()
Explanation: The bind_result() method is used to bind variables to a prepared statement for result storage, and it does not support SQL queries with *.

23
Q

While escaping strings, data is also escaped with the special characters. Options:
a. Yes
b. No

A

Answer: a. Yes
Explanation: When escaping strings, special characters (like quotes) are also escaped to prevent SQL injection and ensure proper query execution.

24
Q

Which keyword is used to create an object of a class in PHP? Options:
a. New
b. Public
c. Object
d. None of the above

A

Answer: a. New
Explanation: The new keyword is used to create an instance (object) of a class in PHP.

25
Q

How many objects can be created for a class? Options:
a. 2
b. 1
c. Multiple
d. Maximum 4

A

Answer: c. Multiple
Explanation: You can create multiple objects from a single class in PHP.

26
Q

Correct syntax to create an object is - Options:
a. $variable=class_name();
b. $variable=new class_name();
c. $variable=new class class_name();
d. new.$variable=class_name();

A

Answer: b. $variable=new class_name();
Explanation: The correct syntax to create an object is to use the new keyword followed by the class name

27
Q

Object is an _____ of a class. Options:

A

Answer: a. Instance
Explanation: An object is an instance of a class, representing a specific realization of the class.

28
Q

We can call a member function using the object of a particular class with different properties. Options:
a. True
b. False

A

Answer: a. True
Explanation: You can call member functions on an object of a class, and those functions can operate on the object’s properties.

29
Q

Member function can access members of____

A

Answer: a. Current object
Explanation: A member function can access the properties and methods of the current object using $this.

30
Q

Constructor functions are automatically called at the time of: Options:
a. Calling of method
b. Constructing an object.
c. Defining class
d. Defining method

A

Answer: b. Constructing an object.
Explanation: Constructor functions are automatically invoked when an object of the class is created.

31
Q

In PHP, which function is used to define a constructor? Options:
a. Construcor()
b. construct()
c. constructor()
d. Construct()

A

Answer: b. __construct()
Explanation: The __construct() method is the correct way to define a constructor in PHP.

32
Q

Which of the following is the correct syntax of escaping strings in MySQLi? Options:

a. mysqli_real_escape_string(conn, escapestrings)
b. mysqli_real_escape_string(conn, escapestrings())
c. mysqli_real_escape_string(conn, escapestrings{})
d. mysqli_real_escape_string(conn, escapestrings[])

A

Answer: a. mysqli_real_escape_string(conn, escapestrings)
Explanation: The correct syntax for escaping strings in MySQLi is mysqli_real_escape_string(connection, string)

33
Q

Constructor is also called as _____ in PHP. Options:

a. Magic functions
b. Static member of class
c. Object of class
d. All of the above

A

Answer: a. Magic functions
Explanation: Constructors are considered “magic methods” in PHP because they have special names that are recognized by the PHP engine.

34
Q

Constructor have: Options:
a. Parameters
b. No parameters
c. Only one argument
d. a or b

A

Answer: d. a or b
Explanation: Constructors can have parameters, but they can also be defined without any parameters.

35
Q

Destructor is called: Options:
a. When destructor defined
b. When object is destructed or the script is stopped.
c. Not called if not defined
d. When constructor passes control to destructor

A

Answer: b. When object is destructed or the script is stopped.
Explanation: The destructor is automatically called when an object is destroyed or when the script ends.

36
Q

In PHP, which function is used to define a destructor? Options:

a. destrucor()
b. destruct()
c. destructor()
d. destruct()

A

Answer: b. __destruct()
Explanation: The __destruct() method is the correct way to define a destructor in PHP.

37
Q

The destructor method cannot accept any argument. Options:

a. False
b. True

A

Answer: b. True
Explanation: The destructor method in PHP cannot accept any parameters.

38
Q

An inherited class is defined by using the _____ keyword. Options:

a. Extends
b. Implements
c. extends
d. implements

A

Answer: a. Extends
Explanation: The extends keyword is used to create a subclass (inherited class) from a parent class in PHP.

39
Q

Which properties of the parent class can be accessed by the child class? Options:
a. Private & public
b. Private & protected
c. Public & protected
d. Only Public

A

Answer: c. Public & protected
Explanation: A child class can access public and protected properties of the parent class, but not private properties.