Phpfox_Error

Description

Error handling for phpFox.

Within a controller you can exit the script by using the display() method like:

  1.  return Phpfox_Error::display('Unable to view this page...');

If using PHP logic that requires triggering a fatal error it can be done with:

  1.  Phpfox_Error::trigger('Missing a variable...'E_USER_ERROR);

The entire script has a built in error system and automatically displays errors when set with:

  1.  Phpfox_Error::set('We have encountered an error');

  • author: Raymond Benc
  • version: $Id: error.class.php 1687 2010-07-22 03:13:27Z Raymond_Benc $
  • copyright: [PHPFOX_COPYRIGHT]

Located in /include/library/phpfox/error/error.class.php (line 31)


	
			
Variable Summary
 static array $aErrors
 static bool $_bDisplay
 static bool $_bSkipError
Method Summary
 static void display (string $sMsg)
 static bool errorHandler (int $nErrNo, string $sErrMsg, string $sFileName, int $nLinenum, array $aVars)
 static array get ()
 static array getDisplay ()
 static unknown isPassed ()
 static void log (string $sMessage, string $sFile, int $iLine)
 static void reset ()
 static bool set (string $sMsg)
 static void setDisplay (bool $bDisplay)
 static void skip (bool $bSkipError)
 static bool trigger (string $sMsg, [constant $sErrorCode = E_USER_WARNING])
 static string _escapeCdata (string $sXml)
Variables
static array $aErrors = array() (line 39)

Holds an ARRAY of all the error messages we set

  • access: private
static bool $_bDisplay = true (line 47)

Holds a BOOL value if we should display the error messages or not

  • access: private
static bool $_bSkipError = false (line 55)

Holds a BOOL value if we should skip the error reporting or not

  • access: private
Methods
static display (line 63)

Displays the error message and directly creates a variable for the template engine

  • access: public
void display (string $sMsg)
  • string $sMsg: Error message you want to display on the current page the user is on.
static errorHandler (line 216)

This method handles the output of the error message PHP returns. We extend the PHP error reporting with providing more information on the error and where in the source code it can be found.

  • return: We only return a BOOL FALSE if we need to skip error reporting, otherwise we echo the output.
  • see: set_error_handler
  • access: public
bool errorHandler (int $nErrNo, string $sErrMsg, string $sFileName, int $nLinenum, array $aVars)
  • int $nErrNo: The first parameter, errno, contains the level of the error raised, as an integer.
  • string $sErrMsg: The second parameter, errstr, contains the error message, as a string.
  • string $sFileName: The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string.
  • int $nLinenum: The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer.
  • array $aVars: The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context.
static get (line 113)

Get all the reported errors thus far set by the method set()

  • return: Returns an ARRAY of error messages. If no errors it returns an empty ARRAY
  • see: self::set()
  • access: public
array get ()
static getDisplay (line 135)

Gets the current display status of error reporting

  • access: public
array getDisplay ()
static isPassed (line 161)

Returns if an error has accured up to this point. This is bassed on anything set by the method set(). This is used with IF conditional statments to see if we can continue with a routine or if an error has occured.

Example usage:

  1.  {
  2.          // Everything is okay do something here...
  3.  }
  4.  else
  5.  {
  6.          // Oh no there was an error. Display error messages here...
  7.  }

  • see: self::set()
  • access: public
unknown isPassed ()
static log (line 423)

Error messages can also be logged into a flat file on the server. The reason for this certain AJAX request or API callbacks may be hard to find error reports and by adding all error reports to a flat file it will help with debugging. This is automatically used with our error handler.

  • see: self::errorHandler()
  • access: public
void log (string $sMessage, string $sFile, int $iLine)
  • string $sMessage: Error message to display
  • string $sFile: Full path to the file
  • int $iLine: Line number of where the error occured
static reset (line 174)

Reset the error messages. We do this automatically at the end of the entire routine to display a page, however if you need to reset it earlier it can be done with this method.

  • access: public
void reset ()
static set (line 99)

Set an error message that can be displayed at a later time

  • return: Always returns FALSE since we encountered an error
  • access: public
bool set (string $sMsg)
  • string $sMsg: Error message you want to display
static setDisplay (line 124)

Sets the display status of error reporting.

  • access: public
void setDisplay (bool $bDisplay)
  • bool $bDisplay: Sets the display status
static skip (line 189)

If debug mode is enabled and you want to make sure to skip error reporting

you can use this method to force us to skip error reporting and then later turn it back on. We mainly use this when dealing with 3rd party libraries since we did not develop the code we are not fully aware of the coding standards applied.

  • access: public
void skip (bool $bSkipError)
  • bool $bSkipError: TRUE to skip error reporting and FALSE to turn error reporting back on.
static trigger (line 80)

Display a warning or error message

  • return: If E_USER_ERROR is enabled we exit() the script, however if not we return FALSE
  • access: public
bool trigger (string $sMsg, [constant $sErrorCode = E_USER_WARNING])
  • string $sMsg: is the Error message
  • constant $sErrorCode: is the valid constant. (eg. E_USER_WARNING will be a warning message and E_USER_ERROR will be a fatal error message)
static _escapeCdata (line 465)

Removes any CDATA from a string.

  • return: New string without CDATA
  • access: private
string _escapeCdata (string $sXml)
  • string $sXml: XML code to parse

Documentation generated on Tue, 28 Sep 2010 10:36:39 +0200 by phpDocumentor 1.4.0a2