Error Handling.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Error Handling.

Post 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!
Last edited by lafever on Wed Apr 09, 2008 12:45 pm, edited 1 time in total.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Re: Error Handling.

Post 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.
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: Error Handling.

Post 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); 
        }
     }
 
Last edited by lafever on Wed Apr 09, 2008 2:49 pm, edited 2 times in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Error Handling.

Post 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
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: Error Handling.

Post 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:
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: Error Handling.

Post 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?
Post Reply