Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you check the existence of a class method in PHP?
1) class_exists()
2) method_exists()
3) function_exists()
4) is_method()
Answer : Option 2
Which PHP function is used to check if a file is readable?
1) is_readable()
2) readable()
3) can_read()
4) file_readable()
Answer : Option 1
Which function is used to perform a case-insensitive string comparison in PHP?
1) strcasecmp()
2) strcmp()
3) stristr()
4) strtoupper()
Answer : Option 1
How can you retrieve the client browser’s details in PHP?
1) $_SERVER["HTTP_USER_AGENT"]
2) $_SERVER["BROWSER_INFO"]
3) $_SERVER["CLIENT_BROWSER"]
4) $_SERVER["HTTP_BROWSER"]
Answer : Option 1
What does the `final` keyword in a PHP class mean?
1) The class can be extended
2) The class cannot be extended
3) The class cannot be instantiated
4) The class can only be instantiated once
Answer : Option 2
Which of the following is the correct way to start a heredoc in PHP?
1) <<<HEREDOC
2) <<HEREDOC
3) <<<EOT
4) <<EOT
Answer : Option 3
Which function is used to fetch the next row from a MySQL result set as an object?
1) mysqli_fetch_object()
2) mysqli_fetch_assoc()
3) mysqli_fetch_row()
4) mysqli_fetch_array()
Answer : Option 1
What is the purpose of the `__toString` method in a PHP class?
1) To convert an object to a string
2) To print the class name
3) To convert a string to an object
4) To compare two strings
Answer : Option 1
Which of the following functions can be used to sanitize a string for HTML output in PHP?
1) htmlentities()
2) htmlspecialchars()
3) strip_tags()
4) All of the above
Answer : Option 4
Which function would you use to encode a URL string in PHP?
1) urlencode()
2) urlencode()
3) url_convert()
4) encodeurl()
Answer : Option 1