PHP base class Debug Class Error Class

Source: Internet
Author: User
Tags date define bool exit error code error handling goto variable
Error <?php
//
// +----------------------------------------------------------------------+
// | WHXBB base Class |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 Netfish Software |
// | |
// | AUTHOR:WHXBB (whxbb@21cn.com) |
// +----------------------------------------------------------------------+
//
$id:whxbb.class.php,v 0.1 2001/8/4 12:53:33 YF EXP $
//
Prohibit direct access to this page
if (basename ($http_server_vars[' php_self ')) = = "Whxbb.class.php" {
Header ("http/1.0 404 Not Found";
}

Debug flag, for 1 o'clock, system running in debug state
Define (' Whxbb_debug_flag ', 0);

Predefined for error codes
Ignoring errors
Define (' Whxbb_error_ignore ', 1);
Show Error on page
Define (' Whxbb_error_echo ', 2);
Pop-up error warning and display error
Define (' Whxbb_error_alert ', 4);
Stop a program from running
Define (' Whxbb_error_die ', 8);
Back to the previous page
Define (' Whxbb_error_return ', 16);
Skip to specified page
Define (' Whxbb_error_goto ', 32);

/**
* Purpose
* base class, which encapsulates some common methods in the class
*
* @author: WHXBB (whxbb@21cn.com)
* @version: 0.1
* @date: 2001/12/4
*/
Class Whxbb
{
/**
* Debug Flags
* @access protected
*/
var $_debug;
/**
* Database Connection Flag
* @access Protect
*/
var $_conn;

function Whxbb ()
{
Database connection Flags
Global $_conn;
if (!is_resource ($conn))
Die ("Database connection error";
$this->_conn = $conn;
$this->_debug = Whxbb_debug_flag;
}

/**
* Processing Strings
* @param $str The string to be processed
* @param $act in replaces \ ' out with '
* @access Public
*/
function operatestring (&AMP;$STR, $act)
{
if ($act = = ' in ')
$str = Str_replace ("'", "\ n", $str);
if ($act = ' out ')
$str = str_replace ("\ \", "'", $str);
}
/**
* Determine if a variable is an Error object
*
* @param variables to be judged by $data
* @access Public
* @return bool is true not false
*/
function IsError ($data) {
Return (BOOL) (Is_object ($data) &&
(Get_class ($data) = = "Whxbb_error" | |
Is_subclass_of ($data, "Whxbb_error"));
}
/**
* Determine if a variable is a paging object
*
* @param $data the value to test
* @access Public
* @return bool True if $data is Pager
*/
function Ispager ($data) {
Return (BOOL) (Is_object ($data) &&
(Get_class ($data) = = "Pager" | |
Is_subclass_of ($data, "Pager"));
}
}

/**
* Debug Class
*
* Purpose
*
* Program Tuning Trial
*
* @author: WXHBB (whxbb@21cn.com)
* @version: 0.1
* @date: 2001/8/4
*/
Class Whxbb_debug Extends WHXBB
{
function Whxbb_debug ($msg)
{
$THIS-&GT;WHXBB ();
if ($this->_debug = 1)
{
echo "\n<br>whxbb Debug >>> $msg<br>\n";
}
}
}
/**
* Purpose
* Error handling (triggering error, displaying error)
*
* @author: WHXBB (whxbb@21cn.com)
* @version: 0.1
* @date: 2001/8/4
*/
Class Whxbb_error extends Whxbb
{
/**
* Error message
* @access protected
*/
var $_errno;
/**
* Error code
* @access protected
*/
var $_errmsg;
/** error mode See "Predefined Code for errors" * *
var $_reportmethod;

/**
* Construct an Error object
* @param $errmsg error message, incorrect character description
* @param $errno error code, wrong code
* @param $reportmethod error mode, see "Predefined Error Codes"
* @param $param1 parameter One, such as the URL of the page when you jump to the specified page
* @param $param2 parameter two retention
* @access Public
*/
function Whxbb_error ($errmsg, $errno, $reportmethod = whxbb_error_ignore, $param1 = ', $param2 = ')
{
$THIS-&GT;WHXBB ();
$this->_errmsg = $errmsg;
$this->_errno = $errno;
$this->_reportmethod = $reportmethod;
Switch ($reportmethod)
{
Case Whxbb_error_ignore:
Break
Case Whxbb_error_echo:
Echo $errmsg;
Break
Case Whxbb_error_alert:
Js::alert ($ERRMSG);
Break
Case Whxbb_error_die:
$this->close ();
Exit
Break
Case Whxbb_error_die + Whxbb_error_alert:
Js::alert ($ERRMSG);
$this->close ();
Exit
Break
Case Whxbb_error_die + Whxbb_error_echo:
Echo $errmsg;
$this->close ();
Exit
Break
Case Whxbb_error_alert + Whxbb_error_return:
Js::alert ($ERRMSG);
Js::back ();
Break
Case Whxbb_error_return:
Js::back ();
Break
Case Whxbb_error_goto:
Js::goto ($PARAM1);
Break
Case Whxbb_error_goto + Whxbb_error_alert:
Js::alert ($ERRMSG);
Js::goto ($PARAM1);
Break
}
New Whxbb_debug ($errno. ":". $errmsg);
}
/**
* Get error message for wrong object
*/
function getmsg ()
{
Return $this->_errmsg;
}
/**
* To get the wrong object of the error generation buy
*/
function Getno ()
{
Return $this->_errno;
}
}
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.