Hi,
I used the Function:
set_error_handler(array($this->Log,'BuildPHPErrorLog'));
to make my LogController Class (function "BuildPHPErrorLog") handle the Errors.
BuildPHPErrorLog creates a Log Object, fills it with ErrorMessage, Code, Line, File and Context and then saves it to the Mysql DB.
$Parameter = array(
"LogType" => 0, # this means php error
"ExceptionMessage" => $ErrorString,
"ExceptionCode" => $ErrorNo,
"ExceptionFile" => $ErrorFile,
"ExceptionLine" => $ErrorLine,
);
$Log = new Log($Parameter);
$Log->SaveToDb($this->DB);
After that I had several new Errors in my DB, such as a warning from my date() function, because I missed to set up a Timezone or complains why I hardly use "if(isset($var)) { use $var; }", most of the time I use $var without checking for existance.
These are some of the "new" errors I detected, but there are some other Errors my Function doesnt handle, such as:
$div = 10 / 0;
This should throw a "Division by 0"-Error or something like that.
@strpos(); should throw a "I need at least 1 Parameter" Error ...
but there´s nothing to find in the DB...
So I think "Div by 0" and some other Errors are of some kind of other Type, which issnt affected by
"set_error_handler(array($this->Log,'BuildPHPErrorLog'));"
So I need help ^^
Different Types of Errors in php?
Moderator: General Moderators
-
Machiavelli79
- Forum Newbie
- Posts: 1
- Joined: Fri Jan 23, 2009 10:22 am
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Different Types of Errors in php?
There are many levels of error reporting. You have probably change the setting somehow:
http://www.php.net/manual/en/function.e ... orting.php
http://www.php.net/manual/en/security.errors.php
http://www.php.net/manual/en/function.e ... orting.php
http://www.php.net/manual/en/security.errors.php
(#10850)
Re: Different Types of Errors in php?
Hi Machiavelli79,
Calling strpos() with no parameters will throw an E_WARNING error, "Wrong parameter count for strpos()." I was able to to intercept E_WARNING errors with the following code:
Though this didn't change anything for me, one recommendation might be to try setting the value for $error_types to E_ALL:
As this is an E_WARNING error, you might want to check with your logging class to see if it is filtering out any errors that don't meet a certain threshold.
-Chewbacca
Calling strpos() with no parameters will throw an E_WARNING error, "Wrong parameter count for strpos()." I was able to to intercept E_WARNING errors with the following code:
Code: Select all
function errorHandler($errno, $errstr, $errfile, $errline, array $errcontext) {
echo 'Error handler: ' . $errno . ' - ' . $errstr . '<hr />';
}
set_error_handler('errorHandler', E_ALL);
// Changing the error_reporting level will not affect your error_handler
error_reporting(0);
// Throw an E_WARNING error
strpos();
Code: Select all
set_error_handler(array($this->Log,'BuildPHPErrorLog'), E_ALL)-Chewbacca
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Different Types of Errors in php?
Not only is he a new Devnet member, and gives an excellent answer, but he's first-mate on a ship that might suit our needs. 
(#10850)