Q.61 In PHP, what security measure should be implemented to protect sensitive data, like passwords, stored in a database?
A. Storing them as plain text with unique identifiers
B. Encrypting them using reversible encryption
C. Hashing them using a cryptographic hash function
D. Compressing them before storage
Answer. C
Q.62 What is the primary purpose of using prepared statements in PHP?
A. To optimize query execution speed
B. To improve code readability
C. To protect against SQL injection attacks
D. To handle large datasets
Answer. C
Q.63 Spot the mistake in this PHP code for reading a file:
$file = fopen(“file.txt”, “r”);
$data = fread($file, filesize(“file.txt”));
fclose($file); echo $data;
A. There is no mistake
B. Missing error handling for file opening
C. Incorrect use of filesize()
D. The file is not closed properly
Answer. B
Q.64 Identify the error in this PHP file handling code:
$file = fopen(“nonexistent.txt”, “r”); fwrite($file, “Data”); fclose($file);
A. The file does not exist
B. Incorrect mode for fwrite
C. Syntax error
D. No error in the code
Answer. A
Q.65 In PHP, what does the file_put_contents() function do when the FILE_APPEND flag is used?
A. Replaces the content of the file
B. Deletes the file and creates a new one
C. Appends content to the end of the file
D. Creates a new file
Answer. C
Q.66 What is the result of the following PHP code?
$file = fopen(“test.txt”, “w”); fwrite($file, “Hello, World!”); fclose($file);
A. A new file named “test.txt” is created with “Hello, World!” inside
B. An error occurs
C. Nothing happens
D. The file “test.txt” is deleted
Answer. A
Q.67 In PHP, how do you check if a file exists and is readable?
A. Using is_readable() and file_exists()
B. Using file_exists()
C. Using can_read()
D. Using fopen() and checking if it’s false
Answer. A
Q.68 What does the PHP file_get_contents() function do?
A. Reads the entire file into a string
B. Deletes the specified file
C. Creates a new file
D. Writes content to a file
Answer. A
Q.69 Which file mode in PHP can be used to open a file for both reading and writing, and places the file pointer at the beginning?
A. r+
B. w+
C. a+
D. x+
Answer. A
Q.70 In PHP, which function is used to open a file?
A. fopen()
B. open_file()
C. file_open()
D. open()
Answer. A
Q.71 Spot the mistake in this PHP exception handling:
try {
$value = 10/0;
}
catch (Exception $e) {
echo “Caught exception: “, $e->getMessage();
}
A. Dividing by zero is not caught
B. Incorrect message concatenation
C. No mistake, it will catch and display the exception
D. The variable $e is not defined
Answer. A
Q.72 Identify the error in this PHP error handling code:
try {
//code } catch() {
echo “Error occurred”;
}
A. Empty catch block
B Missing exception type in catch block
C. Syntax error in try block
D. No error in the code
Answer. B
Q.73 Given the code:
$num = -1;
try {
if($num < 0) { throw new Exception(“Negative number”); } } catch (Exception $e) { echo $e->getMessage();
}
What will be output?
A. Negative number
B. Nothing
C. Exception in script
D. Error
Answer. A
Q.74 What will happen if an exception is not caught in PHP?
A. The script will continue running
B. A fatal error will occur
C. The exception will be ignored
D. The script will pause
Answer. B
Q.75 What is the difference between exceptions and errors in PHP?
A. Exceptions can be caught and handled, errors cannot
B. Errors are for system-level issues, exceptions are for script issues
C. Exceptions are fatal, errors are not
D. There is no difference
Answer. A