PHP MCQs for Senior Developer - Mercer Mettl Online Assessment
Here are some multiple-choice questions (MCQs) that could be suitable for assessing the skills of a senior PHP developer in a Mettl test:
1. What does PHP stand for?
A. Personal Hypertext Processor
B. Preprocessed Hypertext Pages
C. PHP: Hypertext Preprocessor
D. Preprocessor HyperText Programming
Correct Answer: C
2. Which of the following functions is used to open a file for writing in PHP?
A. fopen("filename", "r")
B. fopen("filename", "w")
C. fopen("filename", "a")
D. file_open("filename", "w")
Correct Answer: B
3. What is the purpose of the mysqli_real_escape_string function in PHP?
A. Converts special characters to HTML entities
B. Escapes special characters in a string for use in an SQL statement
C. Validates an email address
D. Removes HTML and PHP tags from a string
Correct Answer: B
4. In PHP, what is the purpose of the isset() function?
A. Checks if a variable is set and not null
B. Determines if a file exists
C. Checks if a function is defined
D. Validates if an array key exists
Correct Answer: A
5. How can you start a session in PHP?
A. init_session()
B. session_start()
C. start_session()
D. open_session()
Correct Answer: B
6.What is the difference between == and === in PHP?
A. Both are used for assignment
B. == compares values, === compares values and types
C. == compares values and types, === compares values
D. There is no difference, they are interchangeable
Correct Answer: B
7.Which superglobal variable is used to access form data sent with the HTTP POST method?
A. $_POST
B. $_GET
C. $_REQUEST
D. $_SERVER
Correct Answer: A
8.What is the purpose of the __construct method in PHP?
A. To create a new object instance
B. To initialize properties of an object when it is created
C. To destroy an object
D. To define a constant
Correct Answer: B
9.How can you prevent SQL injection in PHP?
A. Use mysql_escape_string()
B. Use prepared statements with parameterized queries
C. Use htmlspecialchars() on all input
D. Use addslashes() on all input
Correct Answer: B
10.What is the correct way to include an external PHP file named "functions.php" in another PHP file?
A. include functions.php;
B. require "functions.php";
C. include("functions.php");
D. import functions.php;
Correct Answer: C
11.What will be the output of the following code?
$a = 10;
$b = 20;
echo $a.$b;
A. 1020
B. 30
C. 102
D. Error
Correct Answer: A
12.Consider the following code snippet. What will be the output?
$x = "5";
$y = 10;
echo $x + $y;
A. 15
B. 510
C. 5
D. Error
Correct Answer: A
13.What is the output of the following code?
$var = 5;
echo $var++ + ++$var;
A. 12
B. 11
C. 10
D. 13
Correct Answer: A
//5+1+7
//echo $var++ + ++$var;
14. What will be the output of the following code?
$array = [1, 2, 3, 4, 5];
unset($array[2]);
echo count($array);
A. 4
B. 5
C. 3
D. Error
Correct Answer: A
15. What is the output of the following code?
echo str_replace("world", "PHP", "Hello world!");
A. Hello PHP!
B. Hello PHP
C. Hello world!
D. Error
Correct Answer: A
16. Consider the following code snippet. What will be the output?
$a = "5 apples";
$b = "2 pears";
echo $a + $b;
A. 7
B. 52 pears
C. 5 apples2 pears
D. Error
Correct Answer: A (output will have a warning)
17. What is the output of the following code?
echo count(NULL);
A. 0
B. 1
C. Error
D. null
Correct Answer: C
18. What will be the output of the following code?
echo "a" + "b";
A. 2
B. ab
C. Error
D. 0
Correct Answer: C
19. What is the output of the following code?
$x = 5;
echo $x . ++$x;
A. 56
B. 65
C. 66
D. 11
Correct Answer: C
20. What is the output of the following code?
$s = "5d5";
var_dump(++$s);
var_dump(++$s);
A. string(3) "66" string(3) "77"
B. Error
C. string(3) "5d6" string(3) "5d7"
D. string(3) "6" string(3) "7"
Correct Answer: C
21. Consider the code below. What will be the output?
$a = "hello";
echo ++$a;
A. Error
B. hellp
C. Ifmmp
D. helloworld
Correct Answer: C
22.What is the output of the following code?
echo 1 == true;
A. true
B. false
C. Error
D. 1
Correct Answer: 1
Comments
Post a Comment