Sample questions
Question 1Medium
Run time warning refers to__.
- E_ERROR
- E_USER_WARNING
- E_CORE
- E_WARNING
Answer: D. E_WARNING
Explanation
Run-time warnings (non-fatal errors). Execution of the script is not halted.
Step-by-step solution
- Run time warning occurs during script execution.
- It does not stop the script from running.
- E_WARNING is the PHP constant for run-time warnings.
- Other options are for errors or core issues.
- Correct answer is E_WARNING.
Why the other options are wrong
- A. E_ERROR is a fatal run-time error that stops the script, not a run-time warning.
- B. E_USER_WARNING is raised by user code with trigger_error, not by the PHP run-time itself.
- C. E_CORE is not the constant for run-time warnings; those are reported as E_WARNING.
Tip: Remember: E_WARNING is used for run-time warnings in PHP.
Question 2Medium
The error reporting directive __ the reporting sensitivity level.
- Selects
- Determines
- Errors
- Chooses.
Answer: B. Determines
Explanation
The error reporting directive Determines the reporting sensitivity level.
During the development stage, you'll likely want all errors to be reported. Therefore, consider setting the directive like this:
error_reporting = E_ALL
Step-by-step solution
- The sentence says the error reporting directive blank the reporting sensitivity level.
- The explanation says the directive Determines the reporting sensitivity level, which fits the sentence.
- So option B, Determines, is the answer.
Why the other options are wrong
- A. Selects does not fit, because the directive sets the level rather than selecting one.
- C. Errors is a noun for the messages, not the verb the sentence needs.
- D. Chooses is not the word that fits what the directive does.
Tip: For fill-in-the-blank questions, put each option in the blank and keep the one that reads correctly.
Question 3Medium
During developing stage, which of the directive used for all errors to be reported?
- Error_reporting= All_error & E_strict
- E_All | E_Parse
- Error_reporting =E_All and E_STRICT
- None of the above
Answer: C. Error_reporting =E_All and E_STRICT
Explanation
The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script. If the optional level is not set, error_reporting() will just return the current error reporting level.
Step-by-step solution
- While developing, you want every error and notice shown.
- The directive is
error_reporting set to E_ALL together with E_STRICT. - Option A uses a made-up constant All_error.
- Option B lacks the directive name and misses notices, so option C is the best match.
Why the other options are wrong
- A.
All_error is not a PHP constant. - B. E_ALL | E_Parse is not written as the directive and is not the full development setting.
- D. Option C gives the intended setting.
Tip: Development: error_reporting = E_ALL (plus E_STRICT in older PHP).
Question 4Medium
User generated error refers to.
- E_USER_ERROR.
- E_ERROR
- E_USER_NOTICE
- E_NOTICE
Answer: A. E_USER_ERROR.
Explanation
User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
E_ERROR are fatal run-time errors. These indicate errors that cannot be recovered from, such as a memory allocation problem. Execution of the script is halted.
Step-by-step solution
- User generated error is created using
trigger_error() in PHP. E_USER_ERROR is the correct error type for user-generated errors.E_ERROR is a fatal run-time error, not user-generated.E_USER_NOTICE and E_NOTICE are warnings, not errors.- Correct answer is 0 as it matches
E_USER_ERROR.
Why the other options are wrong
- B. E_ERROR is a fatal run-time error raised by PHP itself, not an error raised by user code.
- C. E_USER_NOTICE is a user-raised notice, a minor message, not an error.
- D. E_NOTICE is a minor run-time notice from PHP, not a user-generated error.
Tip: Remember: E_USER_ERROR is for user-triggered errors, not system faults.
Question 5Medium
Which of the following correct error level description?
- E_USER_ERROR it refers user-generated notices.
- E_USER_ERROR it refers user-generated errors.
- E_USER_ERROR it refers user-generated warning
- None
Answer: B. E_USER_ERROR it refers user-generated errors.
Explanation
E_USER_ERROR is a user-generated error level, raised with trigger_error(). Option A describes notices and option C describes warnings; those are E_USER_NOTICE and E_USER_WARNING.
Step-by-step solution
- The question asks which error level description is correct.
- E_USER_ERROR is the PHP error level for errors generated by the user.
- So option B, user-generated errors, is the answer.
Why the other options are wrong
- A. Notices are E_USER_NOTICE, not E_USER_ERROR.
- C. Warnings are E_USER_WARNING, not E_USER_ERROR.
- D. Option B is correct, so None is wrong.
Tip: The middle word of an E_USER_ constant tells the level: NOTICE, WARNING or ERROR.
Question 6Medium
How to get name of the file throwing the exception?
getFile()getName()getCode()getMessage()
Answer: A. getFile()
Explanation
Exception::getFile() Gets the file in which the exception occurred
final public string Exception::getFile ( void )
Step-by-step solution
- The question asks how to get the name of the file where an exception was thrown.
- The explanation says Exception::getFile() gets the file in which the exception occurred.
- So the answer is getFile(), option A.
Why the other options are wrong
- B. getName() is not a method for the file of an exception.
- C. getCode() returns the exception code, not the file.
- D. getMessage() returns the error message, not the file.
Tip: Exception methods: getMessage for the text, getCode for the code, getFile for the file, getLine for the line.
Question 7Medium
Which of the following statement is false for php error and logging?
- The error and logging functions are part of the PHP core
debug_backtrace() generates a backtrace- Both a and c
trigger_error() and user_error() are different
Answer: D. trigger_error() and user_error() are different
Explanation
PHP function user_error() generates a user-level error or warning or notice.
The function can be used either along with the built-in error handler, or with a user defined function which is set as the new error handler (set_error_handler()).
If you want to generate a specific response to an exception at runtime, using this function is useful.
This function is an alias of trigger_error().
Step-by-step solution
- The question asks which statement about PHP error and logging is false.
- Error and logging functions are part of PHP core, and debug_backtrace() generates a backtrace, so those statements are true.
- user_error() is an alias of trigger_error(), so the two are the same function.
- The false statement is option D, so the correct answer is option D.
Why the other options are wrong
- A. This statement is true, so it is not the false one.
- B. This statement is true, so it is not the false one.
- C. It depends on the true statements above, so it is not the false one.
Tip: For which is false questions, check each statement and keep the one that breaks a known fact.
Question 8Medium
Which of the following statement is the default exception constructor?
Thrown exception()Throw new exception()Throw new $exception()- None of these.
Answer: B. Throw new exception()
Explanation
Throw new exception() is default exception constructor
Step-by-step solution
- The question asks which statement is the default form for throwing an exception.
- The explanation gives throw new exception() as the default exception constructor form.
- So option B, throw new exception(), is the answer.
Why the other options are wrong
- A. Thrown exception() has the wrong keywords and order.
- C. Using a variable as the class name is not the default form.
- D. Option B is the answer, so none of these is wrong.
Tip: The usual form is throw new ClassName(message).
Question 9Medium
Explain the different types of errors in PHP.
- Notices.
- Warnings.
- Fatal errors.
- All of these.
Answer: D. All of these.
Explanation
Notices, Warnings and Fatal errors are the types of errors in PHP
Notices:
Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.
Warnings:
Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.
Fatal errors:
Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.
Step-by-step solution
- The question asks for the types of errors in PHP.
- The explanation lists notices, warnings and fatal errors as the types.
- All three are listed, so option D, All of these, is the answer.
Why the other options are wrong
- A. Notices are a type, but warnings and fatal errors are types too.
- B. Warnings are a type, but notices and fatal errors are types too.
- C. Fatal errors are a type, but notices and warnings are types too.
Tip: Notices are minor, warnings do not stop the script, and fatal errors stop it.
Question 10Medium
Which is /are following function returns an associate array consisting of the type,message,file and line of last occurring error.?
- error_get_last
- error_file_last
- error_line_last
- error_massage_last
Answer: A. error_get_last
Explanation
The error_get_last() function gets the last error that occured.
This funtion returns the last occured error in an array, or NULL if no errors have occured.
The error array returned contains 4 keys and values:
[type] - Error type
[message] - Error message
[file] - The file where the error occurred
[line] - The line where the error occurred
Step-by-step solution
- Error_get_last returns an array with type, message, file, and line of last error.
- Other options do not return all four keys as required.
- Correct function is error_get_last.
- Final answer: A (error_get_last).
Why the other options are wrong
- B. error_file_last is not a PHP function; the real one is error_get_last().
- C. error_line_last is not a PHP function; the real one is error_get_last().
- D. error_massage_last is not a PHP function; the real one is error_get_last().
Tip: Remember error_get_last for full error data.
Practise all 10 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →