Site icon sharedsapience.info

PHP Error Quiz: All Error Functions [2019]

The debug_backtrace PHP error function, sized for mobile viewing.

An image of the debug_backtrace() PHP error function, sized for mobile viewing.

HOW THE QUIZ WORKS:

Clicking the ‘randomize’ button situated above the reference table generates a new table whereby the function descriptions, function syntaxes, and function return values are randomized. The quiz involves matching the function descriptions, function syntaxes, and function return values to the correct function name. Information relating to the randomization of table cells will be displayed for three seconds, before disappearing.

On a desktop computer, table elements are selected by left-clicking the desired table cell and holding the left click in the mouse down position for one second before releasing the left click. The text inside the table cell will turn red to indicate that the one-second mouse left-click has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second left mouse-click process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second left mouse-click process on the original table cell.

To select a table element on a touchscreen device (mobile, tablet), simply touch the desired table cell and maintain the touch for one second before removing your finger from the screen. The text inside the table cell will turn red to indicate that the one-second touch has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second touch process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second touch process on the original table cell.

Normal touchscreen scrolling behaviour is exhibited by the cells with a light green background; cells without a light green background will not respond to normal touchscreen scrolling. The table is positioned in such a way that the user can also initiate touchscreen scrolling by swiping to the right or left of the table.

When a row consists of the correct function name, function description, function syntax, and function return value, the background colour of the row will change from ‘transparent’ to ‘khaki’; this provides visual feedback that the row is complete.

Once the entire table is complete, a paragraph of feedback will congratulate the user and provide the following information: date and time of quiz commencement; date and time of quiz completion; and the length of time it took the user to complete the quiz.

VIEWPORT OPTIONS:

An example of the layout designed for mobile phones
An example of the layout designed for tablets
An example of the layout designed for desktop computers

PURPOSE:

This webpage serves two purposes:

  1. It provides a reference table for the PHP error functions, with information extracted and condensed from w3schools.com and php.net.
  2. It enables users to complete a quiz related to the PHP error functions.

USAGE:

For each error function there are four table cells of information: the function name; the function description; the function syntax; and the function return value. There are three layouts available – ‘mobile‘, ‘tablet‘, and ‘desktop‘.

Click the relevant button below to display the PHP error functions reference table, sized appropriately for the desired viewport. A ‘RANDOMIZE‘ button appears above the reference table once the viewport is selected; clicking this button facilitates the commencement of a quiz.



Click the ‘RANDOMIZE‘ button to randomize the functional descriptions, the functional syntaxes, and the functional return information.


FUNCTION NAME FUNCTION DESCRIPTION FUNCTION SYNTAX FUNCTION RETURN VALUE
debug_backtrace()

[debug_backtrace – Generates a backtrace]

This function generates a PHP backtrace, useful for debugging purposes. debug_backtrace(options [optional parameter, with a default value of DEBUG_BACKTRACE_PROVIDE_OBJECT], limit [optional parameter, with a default value of 0]);

[Possible values for the options parameter as of PHP 5.3.6: DEBUG_BACKTRACE_PROVIDE_OBJECT (default); and DEBUG_BACKTRACE_IGNORE_ARGS. As of PHP 5.4.0, the limit parameter can be used to limit the number of stack frames returned.]

debug_backtrace(): returns an array of associative arrays, with the following elements — function, line, file, class, object, type, and args.
debug_print_backtrace()

[debug_print_backtrace – Prints a backtrace]

This function prints a PHP backtrace, useful for debugging purposes. It prints eval()ed stuff, included/required files, and function calls. debug_print_backtrace(options [optional parameter, with a default value of 0], limit [optional parameter, with a default value of 0]);

[options can also represent the value DEBUG_BACKTRACE_IGNORE_ARGS. As of PHP 5.4.0, limit can be used to limit the number of stack frames printed.]

debug_print_backtrace(): no value is returned [VOID].
error_clear_last()

[error_clear_last – Clear the most recent error]

This function clears the most recent [‘last’] errors, making them unable to be retrieved with error_get_last(). error_clear_last(); error_clear_last(): no value is returned [void].
error_get_last()

[error_get_last – Get the last occurred error]

This function returns [‘gets’] information about the most recent [‘last’] error that occurred. error_get_last(); error_get_last(): returns an associative array describing the last error, comprised of the following elements: type; message; file; and line. If the error has been caused by a PHP internal function, message begins with its name. Returns NULL if there hasn’t been an error yet.
error_log()

[error_log – Send an error message to the defined error handling routines]

This function transmits an error message to the web server’s error log or to a file. Possible message_type values are: 0 [default – sent to PHP’s system logger, the details of which are specified in the error_log configuration directive]; 1 [message is sent via email to the destination address]; 3 [message is appended to the destination address – a newline is NOT automatically added to the end of message]; and 4 [sent directly to the SAPI logging handler]. error_log(message, message_type [optional parameter, with a default value of 0], destination [optional parameter], extra_headers [optional parameter]);

[extra_headers is only used when message_type is set to 1. This message type uses the same internal function as mail() does.]

error_log(): returns TRUE on success; FALSE on failure. This function is NOT binary safe and should NOT contain the null character. base64_encode(), rawurlencode(), or addslashes() should be called as appropriate, prior to calling error_log().
error_reporting()

[error_reporting – Sets which PHP errors are reported]

This function sets the error_reporting directive at runtime. The level remains set for the runtime duration of the script. If level is not set, this function simply returns the current error reporting level. error_reporting(level [optional parameter]);

[Using named constants is strongly encouraged for the level parameter’s future proof-ability. Numerical [named] error constants: 1 [E_ERROR]; 2 [E_WARNING]; 4 [E_PARSE]; 8 [E_NOTICE]; 16 [E_CORE_ERROR]; 32 [E_CORE_WARNING]; 64 [E_COMPILE_ERROR]; 128 [E_COMPILE_WARNING]; 256 [E_USER_ERROR]; 512 [E_USER_WARNING]; 1024 [E_USER_NOTICE]; 2048 [E_STRICT]; 4096 [E_RECOVERABLE_ERROR]; 8192 [E_DEPRECATED]; 16384 [E_USER_DEPRECATED]; and 32767 [E_ALL].]

error_reporting(): returns the old error_reporting level or the current level if no level parameter is passed.
restore_error_handler()

[restore_error_handler – Restores the previous error handler function]

This function is used to revert to [‘restore’] the previous error handler (either the built-in or user-defined function) after changing the error handler function using set_error_handler(). restore_error_handler(); restore_error_handler(): this function always returns TRUE.
restore_exception_handler()

[restore_exception_handler – Restores the previously defined exception handler function]

This function is used to revert to [‘restore’] the previous exception handler (either the built-in or user-defined function) after changing the exception handler function using set_exception_handler(). restore_exception_handler(); restore_exception_handler(): this function always returns TRUE.
set_error_handler()

[set_error_handler – Sets a user-defined error handler function]

This function sets a user function [error_handler] to handle errors in a script. The standard PHP error handler will be bypassed for the error types specified by error_types unless the callback function returns FALSE. If the statement that caused the error was prefixed by the ‘@‘ character, the value of error_reporting will be 0. It is the programmer’s responsibility to die()/exit() if necessary; if the error handler function returns, script execution will continue with the statement following the one that caused the error. set_error_handler(error_handler, error_types [optional parameter, with a default value of E_ALL | E_STRICT], context [optional parameter]);

[NULL may be passed as the callable error_handler parameter, to reset this handler to its default state; an array containing an object reference and a method name can also be given. Otherwise, error_handler is a callback with the following signature:
handler(errno, errstr, errfile [optional parameter], errline [optional parameter], errcontext [optional parameter]);]

set_error_handler): returns a string containing the previously defined error handler (if any); NULL is returned if the built-in error handler is used or an invalid callback is passed. If the last error handler was a class method, an indexed array with the class and the method name is returned.
set_exception_handler()

[set_exception_handler – Sets a user-defined exception handler function]

This function sets the default exception handler if an exception is not caught within a try/catch block. Once the exception_handler is called, execution stops. set_exception_handler(exception_handler);

[The method signature of the callable exception_handler prior to PHP 7: handler(exception). From PHP 7+, the method signature is as follows: handler(throwable). Providing an explicit Exception-type hint for the callable‘s parameter will cause issues with the changed exception hierarchy in PHP 7. This handler can be reset to its default state by passing NULL as the callable‘s parameter.]

set_exception_handler(): the name of the previously-defined exception handler is returned on success. NULL is returned on error or if no exception handler was previously-defined.
trigger_error()

[trigger_error – Generates a user-level error/warning/notice message]

This function is used to trigger a user error condition. It can be used in conjunction with a user-defined function that has been set as the new error handler using set_error_handler(); it can also be used with the built-in error handler. trigger_error() is useful when a particular response needs to be generated in response to an exception at runtime. trigger_error(error_message, error_type [optional parameter, with a default value of E_USER_NOTICE]);

[error_message is limited to 1024 bytes in length; additional characters will be truncated. HTML entities are not escaped; htmlentities() should be used if the error is to be displayed in a browser. error_type only works with the E_USER family of constants.]

trigger_error(): returns FALSE if the wrong error_type is specified; TRUE otherwise.

Web design certified by:
Click images for proof of certification.


Exit mobile version