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 {@link SS_Log}. For configuration information, see the {@link SS_Log} class documentation.

Config options

log_errors_to String
friendly_error_header string
friendly_error_httpcode bool Set to true to enable friendly errors to set a http response code corresponding to the error.
friendly_error_detail string

Methods

static 
show($val, $showHeader = true)

Show the contents of val in a debug-friendly way.

static array
caller()

Returns the caller for a specific method

static 
endshow(mixed $val)

Close out the show dumper

static 
dump(mixed $val)

Quick dump of a variable.

static unknown
text(unknown_type $val)

??

static 
message($message, $showHeader = true)

Show a debugging message

static void
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.

static 
log($message)

Log to a standard text file output.

static 
loadErrorHandlers()

Load error handlers into environment.

static 
noticeHandler($errno, $errstr, $errfile, $errline, $errcontext)

No description

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.

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).

static string
friendlyError(int $statusCode = 500, string $friendlyErrorMessage = null, string $friendlyErrorDetail = null)

Render a user-facing error page, using the default HTML error template rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link SS_HTTPResponse} class the keep dependencies minimal.

static DebugView
create_debug_view()

Create an instance of an appropriate DebugView object.

static 
showError($errno, $errstr, $errfile, $errline, $errcontext, $errtype)

Render a developer facing error page, showing the stack trace and details of the code where the error occured.

static 
showLines(string $errfile, int $errline)

Utility method to render a snippet of PHP source code, from selected file and highlighting the given line number.

static 
require_developer_login()

Check if the user has permissions to run URL debug tools, else redirect them to log in.

Details

at line 64
static show($val, $showHeader = true)

Show the contents of val in a debug-friendly way.

Debug::show() is intended to be equivalent to dprintr()

Parameters

$val
$showHeader

at line 90
static array caller()

Returns the caller for a specific method

Return Value

array

at line 106
static endshow(mixed $val)

Close out the show dumper

Parameters

mixed $val

at line 121
static dump(mixed $val)

Quick dump of a variable.

Parameters

mixed $val

at line 131
static unknown text(unknown_type $val)

??

Parameters

unknown_type $val

Return Value

unknown

at line 169
static message($message, $showHeader = true)

Show a debugging message

Parameters

$message
$showHeader

at line 195
static void 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.

Parameters

string $msg
string $prefix (optional)

Return Value

void

at line 207
static log($message)

Log to a standard text file output.

Parameters

$message string to output

at line 224
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).

at line 229
static noticeHandler($errno, $errstr, $errfile, $errline, $errcontext)

Parameters

$errno
$errstr
$errfile
$errline
$errcontext

at line 261
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.

Parameters

unknown_type $errno
unknown_type $errstr
unknown_type $errfile
unknown_type $errline
unknown_type $errcontext

at line 295
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).

Runtime execution dies immediately once the error is generated.

Parameters

unknown_type $errno
unknown_type $errstr
unknown_type $errfile
unknown_type $errline
unknown_type $errcontext

at line 332
static string friendlyError(int $statusCode = 500, string $friendlyErrorMessage = null, string $friendlyErrorDetail = null)

Render a user-facing error page, using the default HTML error template rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link SS_HTTPResponse} class the keep dependencies minimal.

Parameters

int $statusCode HTTP Status Code (Default: 500)
string $friendlyErrorMessage User-focused error message. Should not contain code pointers or "tech-speak". Used in the HTTP Header and ajax responses.
string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found for this specific status code.

Return Value

string HTML error message for non-ajax requests, plaintext for ajax-request.

at line 386
static DebugView create_debug_view()

Create an instance of an appropriate DebugView object.

Return Value

DebugView

at line 403
static showError($errno, $errstr, $errfile, $errline, $errcontext, $errtype)

Render a developer facing error page, showing the stack trace and details of the code where the error occured.

Parameters

$errno
$errstr
$errfile
$errline
$errcontext
$errtype

at line 453
static showLines(string $errfile, int $errline)

Utility method to render a snippet of PHP source code, from selected file and highlighting the given line number.

Parameters

string $errfile
int $errline

at line 475
static require_developer_login()

Check if the user has permissions to run URL debug tools, else redirect them to log in.