Version: current

# Class Debug

Supports debugging and core error handling.

Attaches custom methods to the default error handling hooks in PHP. Currently, two levels of error are supported:

- Notice
- Warning
- Error

Uncaught exceptions are currently passed to the debug reporter as standard PHP errors.

Errors handled by this class are passed along to `SS_Log`. For configuration information, see the `SS_Log` class documentation.

Package: sapphire\dev
Located at sapphire/dev/Debug.php

## Methods summary

`public static` | # `show( mixed $val, mixed $showHeader = true )` Show the contents of val in a debug-friendly way. Debug::show() is intended to be equivalent to dprintr() Show the contents of val in a debug-friendly way. Debug::show() is intended to be equivalent to dprintr()
`public static` | # `endshow( mixed $val )` Close out the show dumper Close out the show dumper #### Parameters $val mixed $val
`public static` | # `dump( mixed $val )` Quick dump of a variable. Quick dump of a variable. #### Parameters $val mixed $val
`public static unknown` | # `text( unknown_type $val )` ?? ?? #### Parameters $val unknown_type $val #### Returns `unknown` unknown
`public static` | # `message( mixed $message, mixed $showHeader = true )` Show a debugging message Show a debugging message
`public static` | # `header( string $msg, string $prefix = null )` Send a debug message in an HTTP header. Only works if you are on Dev, and headers have not yet been sent. Send a debug message in an HTTP header. Only works if you are on Dev, and headers have not yet been sent. #### Parameters $msg string $msg $prefix string $prefix (optional)
`public static` | # `log( mixed $message )` Log to a standard text file output. Log to a standard text file output. #### Parameters $message $message string to output
`public static` | # `loadErrorHandlers( )` Load error handlers into environment. Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php). Load error handlers into environment. Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php).
`public static` | # `noticeHandler( mixed $errno, mixed $errstr, mixed $errfile, mixed $errline, mixed $errcontext )`
`public static` | # `warningHandler( unknown_type $errno, unknown_type $errstr, unknown_type $errfile, unknown_type $errline, unknown_type $errcontext )` Handle a non-fatal warning error thrown by PHP interpreter. Handle a non-fatal warning error thrown by PHP interpreter. #### Parameters $errno unknown_type $errno $errstr unknown_type $errstr $errfile unknown_type $errfile $errline unknown_type $errline $errcontext unknown_type $errcontext
`public static` | # `fatalHandler( unknown_type $errno, unknown_type $errstr, unknown_type $errfile, unknown_type $errline, unknown_type $errcontext )` Handle a fatal error, depending on the mode of the site (ie: Dev, Test, or Live). Handle a fatal error, depending on the mode of the site (ie: Dev, Test, or Live). Runtime execution dies immediately once the error is generated. #### Parameters $errno unknown_type $errno $errstr unknown_type $errstr $errfile unknown_type $errfile $errline unknown_type $errline $errcontext unknown_type $errcontext
`public static string` | # `friendlyError( integer $statusCode = 500, string $friendlyErrorMessage = null, string $friendlyErrorDetail = null )` Render a user-facing error page, using the default HTML error template rendered by `ErrorPage` if it exists. Doesn't use the standard `SS_HTTPResponse` class the keep dependencies minimal. Render a user-facing error page, using the default HTML error template rendered by `ErrorPage` if it exists. Doesn't use the standard `SS_HTTPResponse` class the keep dependencies minimal. #### Parameters $statusCode int $statusCode HTTP Status Code (Default: 500) $friendlyErrorMessage string $friendlyErrorMessage User-focused error message. Should not contain code pointers or "tech-speak". Used in the HTTP Header and ajax responses. $friendlyErrorDetail string $friendlyErrorDetail Detailed user-focused message. Is just used if no `ErrorPage` is found for this specific status code. #### Returns `string` HTML error message for non-ajax requests, plaintext for ajax-request. #### Uses ``ErrorPage``
`public static` | # `create_debug_view( )` Create an instance of an appropriate DebugView object. Create an instance of an appropriate DebugView object.
`public static` | # `showError( unknown_type $errno, unknown_type $errstr, unknown_type $errfile, unknown_type $errline, unknown_type $errcontext, mixed $errtype )` Render a developer facing error page, showing the stack trace and details of the code where the error occured. Render a developer facing error page, showing the stack trace and details of the code where the error occured. #### Parameters $errno unknown_type $errno $errstr unknown_type $errstr $errfile unknown_type $errfile $errline unknown_type $errline $errcontext unknown_type $errcontext $errtype
`public static` | # `showLines( string $errfile, integer $errline )` Utility method to render a snippet of PHP source code, from selected file and highlighting the given line number. Utility method to render a snippet of PHP source code, from selected file and highlighting the given line number. #### Parameters $errfile string $errfile $errline int $errline
`public static boolean` | # `emailError( string $emailAddress, string $errno, string $errstr, string $errfile, integer $errline, string $errcontext, string $errorType = "Error" )` Dispatch an email notification message when an error is triggered. Dispatch an email notification message when an error is triggered. #### Deprecated 2.5 To create error logs by email, use this code instead: <code> $emailWriter = new SS_LogEmailWriter('my@email.com'); SS_Log::add_writer($emailWriter, SS_Log::ERR); </code> #### Parameters $emailAddress string $emailAddress $errno string $errno $errstr string $errstr $errfile string $errfile $errline int $errline $errcontext string $errcontext $errorType string $errorType "warning" or "error" #### Returns `boolean` boolean
`protected static` | # `log_error_if_necessary( mixed $errno, mixed $errstr, mixed $errfile, mixed $errline, mixed $errcontext, mixed $errtype )` Log the given error, if self::$log_errors is set. Uses the native error_log() funtion in PHP. Log the given error, if self::$log_errors is set. Uses the native error_log() funtion in PHP. Format: [d-M-Y h:i:s] <type> at <file> line <line>: <errormessage> <url> #### Deprecated 2.5 See SS_Log on setting up error file logging
`public static` | # `set_custom_smtp_server( string $server )` #### Deprecated 2.5 See SS_Log on setting up error email notification #### Parameters $server string $server IP-Address or domain
`public static string` | # `get_custom_smtp_server( )` #### Deprecated 2.5 See SS_Log on setting up error email notification #### Returns `string` string
`public static` | # `send_errors_to( string $emailAddress, string $sendWarnings = false )` Send errors to the given email address. Can be used like so: if(Director::isLive()) Debug::send_errors_to("sam@silverstripe.com"); Send errors to the given email address. Can be used like so: if(Director::isLive()) Debug::send_errors_to("sam@silverstripe.com"); #### Deprecated 2.5 See SS_Log on setting up error email notification #### Parameters $emailAddress string $emailAddress The email address to send errors to $sendWarnings string $sendWarnings Set to true to send warnings as well as errors (Default: false)
`public static string` | # `get_send_errors_to( )` #### Deprecated 2.5 See SS_Log on setting up error email notification #### Returns `string` string
`public static` | # `send_warnings_to( string $emailAddress )` #### Deprecated 2.5 See SS_Log on setting up error email notification #### Parameters $emailAddress string $emailAddress
`public static string` | # `get_send_warnings_to( )` #### Deprecated 2.5 See SS_Log on setting up error email notification #### Returns `string` string
`public static` | # `log_errors_to( mixed $logFile = ".sserrors" )` Call this to enable logging of errors. Call this to enable logging of errors. #### Deprecated 2.5 See SS_Log on setting up error file logging
`public static` | # `caller( )`
`public static` | # `backtrace( mixed $returnVal = false, mixed $ignoreAjax = false )` #### Deprecated 2.5 Please use `SS_Backtrace::backtrace()`
`public static` | # `get_rendered_backtrace( mixed $bt, mixed $plainText = false )` #### Deprecated 2.5 Please use `SS_Backtrace::get_rendered_backtrace()`
`public static` | # `require_developer_login( )` Check if the user has permissions to run URL debug tools, else redirect them to log in. Check if the user has permissions to run URL debug tools, else redirect them to log in.

### Magic methods summary

## Properties summary

`protected static string` | $custom_smtp_server | # string Custom mailserver for sending mails. string Custom mailserver for sending mails.
`protected static mixed` | $send_errors_to | # string Email address to send error notifications string Email address to send error notifications
`protected static mixed` | $send_warnings_to | # string Email address to send warning notifications string Email address to send warning notifications
`protected static mixed` | $log_errors_to | # String indicating the file where errors are logged. Filename is relative to the site root. The named file will have a terse log sent to it, and the full log (an encoded file containing backtraces and things) will go to a file of a similar name, but with the suffix ".full" added. String indicating the file where errors are logged. Filename is relative to the site root. The named file will have a terse log sent to it, and the full log (an encoded file containing backtraces and things) will go to a file of a similar name, but with the suffix ".full" added.
`public static string` | $friendly_error_header | # The header of the message shown to users on the live site when a fatal error occurs. The header of the message shown to users on the live site when a fatal error occurs.
`public static string` | $friendly_error_detail | # The body of the message shown to users on the live site when a fatal error occurs. The body of the message shown to users on the live site when a fatal error occurs.
`public static integer` | $headerCount | #

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -