note 19521 deleted from function.set-error-handler by cmb
| From: | cmb@php.net | Date: | Sun, 25 Aug 2019 08:58:05 +0000 |
| Subject: | note 19521 deleted from function.set-error-handler by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211988@lists.php.net to get a copy of this message | ||
Note Submitter: ned at wgtech dot com
----
Just spent two days trying to find some method where a class can handle errors thrown at my
convienience. After fighting with the pitfalls of this problem this is what I came up with. Hope it
helps someone else save a little time. Its nice because all instances of this class will point to
the same array that stores the errors.
class ApplicationObject {
var $error_List;
function ApplicationObject() {
set_error_handler('trapError');
$this->error_List = &trapError();
}
}
function &trapError() {
static $error_Vals = array();
if (func_num_args()==5) { // Error Event has been passed
$error_Vals[] = array( 'err_no' => func_get_arg(0), 'err_text' =>
func_get_arg(1), 'err_file' => func_get_arg(2), 'err_line' =>
func_get_arg(3), 'err_vars'=>func_get_arg(4));
}
if (func_num_args()==0) { // Setup call. Return reference
return $error_Vals;
}
}