Best way to handle errors on a php page?

后端 未结 8 733
傲寒
傲寒 2020-11-30 22:10

Right now my pages look something like this:

if($_GET[\'something\'] == \'somevalue\')
{
    $output .= \'somecode\';

    // make a DB query, fetch a row
           


        
8条回答
  •  萌比男神i
    2020-11-30 22:23

    Handle PHP error and warning in correctly by using error handling functions. ( See example here )

    Best way to Error handling in PHP is, You can stop all error reporting by adding this line in top of your php file -

    error_reporting(0);
    
    //OR
    
    error_reporting('E_ALL');
    
    // Predefined Constant
    

    Error handling in PHP using functions:

    • debug_backtrace — Generates a backtrace
    • debug_print_backtrace — Prints a backtrace
    • error_clear_last — Clear the most recent error
    • error_get_last — Get the last occurred error
    • error_log — Send an error message to the defined error handling routines
    • error_reporting — Sets which PHP errors are reported
    • restore_error_handler — Restores the previous error handler function
    • restore_exception_handler — Restores the previously defined exception handler function
    • set_error_handler — Sets a user-defined error handler function
    • set_exception_handler — Sets a user-defined exception handler function
    • trigger_error — Generates a user-level error/warning/notice message
    • user_error — Alias of trigger_error

    All functions which is listed above are used for Error handling in PHP.

提交回复
热议问题