Page 1 of 1

Error Handling.

Posted: Wed Apr 09, 2008 12:36 pm
by lafever
I was reading php.net's thing on Error Reporting and I must obviously not get it quite well with making your own error handler. I setup a simple one from Zend to learn about it a little bit.

I started getting ridiculous amounts of errors about time zones on date(), strtotime(), etc (Err; 2048.) and Undefined indexes and variables (Err; 8.). But when the error handler isn't there everything works fine.

Should I not use the set_error_handler() and use error_reporting() instead?

Basically what I was trying to do was use set_error_handler() to log and email me when errors happen on my page. Or is there stuff wrong with my code? I really don't think there is because one example for instance is:

Code: Select all

Error code: 8
Error message: Undefined index:  pg
Script name and line number of error: C:\wamp\www\index.php:28
Variable state when error occurred: home

This is the code

Code: Select all

$get = strtolower($_GET['pg']);
Sorry as I have no knowledge of controlling error reports and logs but I desperately need to learn!

Re: Error Handling.

Posted: Wed Apr 09, 2008 12:41 pm
by Citizen
It looks like that variable is not set yet, which is why you are getting that error.

If you did

Code: Select all

 
if(isset($_GET['pg'])){
    $get = strtolower($_GET['pg']);
}
The error should not show up.

Re: Error Handling.

Posted: Wed Apr 09, 2008 12:48 pm
by lafever
I mean really is there a way to ignore little things like this:

Code: Select all

 
Error code: 2048
Error message: Non-static method session::_sess_close() cannot be called statically
Script name and line number of error: Unknown:0
Variable state when error occurred: Array
(
    [0] => home
    [1] => about
    [2] => portfolio
    [3] => articles
    [4] => blog
    [5] => contact
)
 

Code: Select all

 
     // close the session
     function _sess_close() { <--- ERROR
        global $_sess_db;
 
        if ($_sess_db) {
        mysql_close($_sess_db); 
        }
     }
 

Re: Error Handling.

Posted: Wed Apr 09, 2008 2:02 pm
by John Cartwright
Why would you want to? You are using undefined variables. This is a bad thing.

If all you want to do is hide errors, then simply

Code: Select all

error_reporting(0); 
ini_set('display_errors', false);
which can also be set in your php.ini or through .htaccess

Re: Error Handling.

Posted: Wed Apr 09, 2008 2:32 pm
by lafever
The displaying was just for my purposes. I pretty much fixed all my issues with the variables being undefined it's just my session handler with the mysql_close I cannot figure out now.

Is creating an error handler not the way to go then to log data trying to be passed on by a user or if something should go wrong on my site? Nothing will be display on the actual live site error wise. It will all be turned into file logging once I fix all my issues I have with it right now. I just don't want all these tedious things being logged because of my invalid code. :wink:

Re: Error Handling.

Posted: Wed Apr 09, 2008 3:03 pm
by lafever
I got rid of the error by making the close function a static function. Is there a reasoning for this and should all of my functions in the session_set_save_handler be set as static functions?