Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

If the input variable is a string like this “http://www.saåånfoøøundry.com/”, the $url variable after the sanitizing will look like?(a) http://www.saåånfoøøundry.com/(b) http://www.saaanfoooundry.com/(c) http://www.saånfoøundry.com/(d) https://www.sanfoundry.com/The question was asked during a job interview.Asked question is from PHP Filter topic in chapter Error Handling and Exception Handling in PHP of PHP

Answer» RIGHT choice is (d) https://www.sanfoundry.com/

Easiest explanation: Sanitize is NOTHING but TAKE away INVALID characters so therefore the invalid characters like å and ø will be removed.
2.

Which one of the following filter checks if the variable of the specified type exists?(a) filter_has_var(b) filter_var(c) filter_id(d) filter_var_arrayThis question was posed to me by my school teacher while I was bunking the class.My question is taken from PHP Filter topic in division Error Handling and Exception Handling in PHP of PHP

Answer»

Correct answer is (a) filter_has_var

Best explanation: The filter filter_has_var checks if the variable of the specified TYPE EXISTS. Whereas the function filter_id() returns filter ID of a specified filter name. The function filter_var() can VALIDATE and SANITIZE data. The function filter_var_array() can get multiple variables and it optionally filters them.

3.

Which one of the following does not describe a validating filter?(a) Are used to allow or disallow specific characters in a string(b) Are used to validate user input(c) Strict format rules(d) Returns the expected type on success or FALSE on failureThe question was asked during an interview.This is a very interesting question from PHP Filter topic in portion Error Handling and Exception Handling in PHP of PHP

Answer»

Right CHOICE is (a) Are used to allow or disallow specific characters in a STRING

Easy explanation: Validate filter are used to validate user input, it have strict format RULES and it returns the expected TYPE on success or FALSE on failure but ‘are used to allow or disallow specific characters in a string’ describes sanitizing filters.

4.

Which one of the following filter is used to filter several variables with the same or different filters?(a) filter_var_array()(b) filter_var()(c) filter_input(d) filter_input_arrayI got this question during a job interview.I would like to ask this question from PHP Filter in division Error Handling and Exception Handling in PHP of PHP

Answer» RIGHT answer is (a) filter_var_array()

The EXPLANATION: The function filter_var_array() can get multiple variables and it OPTIONALLY FILTERS them. The function is useful for filtering many VALUES without calling filter_var().
5.

What does SPL stand for?(a) Standard PHP Library(b) Source PHP Library(c) Standard PHP List(d) Source PHP ListI had been asked this question during an online interview.This is a very interesting question from Exception Handling topic in division Error Handling and Exception Handling in PHP of PHP

Answer»

Correct OPTION is (a) Standard PHP Library

Easiest EXPLANATION: The standard PHP library(SPL) extends PHP by offering ready-made solutions to commonplace tasks such as FILE ACCESS, iteration of various sorts ETC.

6.

How many types of filtering are present in PHP?(a) 3(b) 2(c) 4(d) NoneI have been asked this question in an interview.The origin of the question is PHP Filter topic in chapter Error Handling and Exception Handling in PHP of PHP

Answer»

The correct answer is (B) 2

The best I can explain: There are two main types of filtering: VALIDATION and sanitization.

7.

How many predefined exceptions does SPL provide access to?(a) 13(b) 14(c) 15(d) 16This question was addressed to me during an interview for a job.My question is taken from Exception Handling in chapter Error Handling and Exception Handling in PHP of PHP

Answer»

The correct CHOICE is (a) 13

The explanation is: It provides 13 EXCEPTIONS: BadFunctionCallException, BadMethodCallException, DOMAINEXCEPTION, InvalidArgumentException, LengthException, LogicException, OutOfBoundsException, OutOfRangeException, OverflowException, RangeException, RuntimeException, UNDERFLOWEXCEPTION, UnexpectedValueException.

8.

You can extend the exception base class, but you cannot override any of the preceding methods because the are declared as__________(a) protected(b) final(c) static(d) privateI have been asked this question in quiz.My query is from Exception Handling topic in section Error Handling and Exception Handling in PHP of PHP

Answer»

The correct option is (B) FINAL

Easy explanation: MARKING a METHOD as final prevents it from being overridden by a SUBCLASS.

9.

Which one of the following is the right description for the method getMessage()?(a) Returns the message if it is passed to the constructor(b) Returns the message if it is passed to the class(c) Returns the message if it is passed to the file(d) Returns the message if it is passed to the objectThe question was asked during an online exam.This intriguing question originated from Exception Handling topic in chapter Error Handling and Exception Handling in PHP of PHP

Answer»

The correct answer is (a) Returns the message if it is passed to the CONSTRUCTOR

To explain: The function GETMESSAGE() GETS the EXCEPTION message. It returns the message if it is passed to the constructor.

10.

Which of the following statements invoke the exception class?(a) throws new Exception();(b) throw new Exception();(c) new Exception();(d) new throws Exception();The question was asked in semester exam.My doubt stems from Exception Handling topic in portion Error Handling and Exception Handling in PHP of PHP

Answer»

The correct option is (b) throw new Exception();

To ELABORATE: throw new Exception(); trigger an exception and each “throw” MUST have at LEAST ONECATCH”.

11.

Which version added the method getPrevious()?(a) PHP 4(b) PHP 5(c) PHP 5.1(d) PHP 5.3I have been asked this question in an international level competition.Query is from Exception Handling topic in portion Error Handling and Exception Handling in PHP of PHP

Answer» RIGHT choice is (d) PHP 5.3

Best explanation: The FUNCTION getPrevious() returns PREVIOUS exception.
12.

How many methods are available for the exception class?(a) 5(b) 6(c) 7(d) 8This question was posed to me during an interview.My doubt is from Exception Handling in division Error Handling and Exception Handling in PHP of PHP

Answer» RIGHT choice is (C) 7

The best EXPLANATION: The seven methods are: getCode(), getFile(), getLine(), GETMESSAGE(), getPrevious(), getTrace(), getTraceAsString().
13.

Which version of PHP was added with Exception handling?(a) PHP 4(b) PHP 5(c) PHP 5.3(d) PHP 6This question was addressed to me in my homework.Question is from Exception Handling in section Error Handling and Exception Handling in PHP of PHP

Answer»

The correct choice is (B) PHP 5

Easy EXPLANATION: Exception HANDLING was ADDED to PHP with the version 5 release, and further enhanced with version 5.3.

14.

Which function is responsible for sending a custom message to the system log?(a) systemlog()(b) syslog()(c) log_system()(d) sys_log()The question was posed to me during an interview for a job.Query is from Error Handling topic in division Error Handling and Exception Handling in PHP of PHP

Answer»

Right CHOICE is (B) syslog()

For EXPLANATION I would say: The FUNCTION syslog() generates a log message that will be distributed by the SYSTEM logger.

15.

Which logging option’s description is if an error occurs when writing to the syslog, send output to the system console?(a) LOG_CONS(b) LOG_NDELAY(c) LOG_ODELAY(d) LOG_PERRORI got this question in a national level competition.The origin of the question is Error Handling in division Error Handling and Exception Handling in PHP of PHP

Answer»

Correct option is (a) LOG_CONS

The explanation is: If there is an error while sending data to the SYSTEM logger, LOG_CONS will write DIRECTLY to the system console.

16.

Which of the following statements causes PHP to disregard repeated error messages that occur within the same file and on the same line?(a) ignore_repeated_errors(b) ignore_repeat_error(c) repeatedly_ignore_error(d) repeated_error_ignoreThis question was addressed to me in a national level competition.Query is from Error Handling topic in chapter Error Handling and Exception Handling in PHP of PHP

Answer»

Correct answer is (a) ignore_repeated_errors

The EXPLANATION is: ignore_repeated_errors will not LOG repeated messages. The repeated errors must occur in the same file on the same line UNLESS ignore_repeated_source is set to TRUE.

17.

Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog() functions?(a) define_variable()(b) define_log_variable()(c) log_variable()(d) define_syslog_variable()The question was posed to me in an interview for internship.My doubt stems from Error Handling topic in section Error Handling and Exception Handling in PHP of PHP

Answer» CORRECT OPTION is (d) define_syslog_variable()

Easy explanation: If you’re running PHP VERSION 5.2.X or older, you need to EXECUTE this function before USING any of the following logging functions.
18.

Which version introduced the function error_get_last()?(a) PHP 4(b) PHP 5(c) PHP 5.2(d) PHP 5.3I have been asked this question in an internship interview.I need to ask this question from Error Handling topic in division Error Handling and Exception Handling in PHP of PHP

Answer» CORRECT answer is (c) PHP 5.2

To explain I would say: This function returns an associative array CONSISTING of the type, message, FILE, and line of the last occurring error.
19.

Say you want to report error concerned about fatal run-time, fatal compile-time error and core error which statement would you use?(a) error_reporting = E_ALL(b) error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR(c) error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR(d) error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERRORThis question was posed to me in an international level competition.My question is based upon Error Handling topic in portion Error Handling and Exception Handling in PHP of PHP

Answer»

Right option is (d) error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR

For EXPLANATION: E_ERROR is a FATAL run-time error, that can’t be recovered from. E_COMPILE_ERROR is a fatal error that occurs while the SCRIPT was being compiled. And E_CORE_ERROR is a fatal error that occurs during the PHP’s ENGINE initial startup.

20.

Which character does the error_reporting directive use to represent the logical operator NOT?(a) /(b) !(c) ~(d) ^The question was asked in a national level competition.This interesting question is from Error Handling in section Error Handling and Exception Handling in PHP of PHP

Answer»

Right ANSWER is (c) ~

For EXPLANATION: The twidle (~) CHARACTER is used to represent the logical operator NOT.

21.

Which version of PHP introduced E_STRICT Error level?(a) PHP 4(b) PHP 5(c) PHP 5.2(d) PHP 5.3I got this question in examination.Question is from Error Handling topic in division Error Handling and Exception Handling in PHP of PHP

Answer» CORRECT option is (b) PHP 5

The best explanation: E_STRICT is PHP version portability suggestions. It is not STRICTLY an error, but it is triggered whenever PHP encounters code that COULD lead to PROBLEMS or forward INCOMPATIBILITIES.
22.

What is the description of Error level E_ERROR?(a) Fatal run-time error(b) Near-fatal error(c) Compile-time error(d) Fatal Compile-time errorThis question was addressed to me by my school teacher while I was bunking the class.This is a very interesting question from Error Handling topic in portion Error Handling and Exception Handling in PHP of PHP

Answer»

The CORRECT answer is (a) Fatal run-time ERROR

The explanation: E_ERROR is a fatal run-time error, that can’t be recovered from and the execution of the SCRIPT is stopped IMMEDIATELY.

23.

How many error levels are available in PHP?(a) 14(b) 15(c) 16(d) 17This question was addressed to me by my college director while I was bunking the class.The doubt is from Error Handling topic in portion Error Handling and Exception Handling in PHP of PHP

Answer» RIGHT answer is (c) 16

Explanation: Whenever the PHP engine encounters any problem that prevents a script from running properly it GENERATES an ERROR message. There are SIXTEEN error levels and each level is represented by an integer VALUE and an associated constant.