Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts

    ignoring error warnings

    I have the following error function:

    function myErrorHandler($errno, $errstr, $errfile, $errline)
    {
    // put your error in file.
    $filename = 'error.txt';
    global $sql;
    $errsql=$sql;
    $errorstr = $errno.$errstr.$errfile.$errline."\n\r".$errsql. "\n\r\n\r\n\r";
    //echo $errrorstr;
    $handle = fopen($filename, 'a');
    fwrite($handle, $errorstr);
    fclose($handle);
    }

    How can I get this to not store warnings such as 8Undefined index: HTTP_REFERER ?

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    undefined index is a E_NOTICE-level error, so setting error-reporting to
    error_reporting(E_ALL ^ E_NOTICE);
    will prevent it from being reported.

    take a look at http://php.net/error-reporting for more details
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts
    instead of error_reporting(0); -- I don't want any errors to show but my error handler picks them up and saves them.
    i don't want to save any warnings

    how do I do this?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Did you even try what GJay suggested? error_reporting(0) is not what he suggested.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,066
    Thanks
    2
    Thanked 319 Times in 311 Posts
    For variables that may or may not exist, write code using the isset() function to avoid the generation of the error in the first place, instead of messing around with the error reporting or error handler after the error has already been generated. Your code will actually run faster by doing this as well.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    A custom error handler in PHP will get to handle all errors it can - it doesn't use the error_reporting setting to see if it should handle an error or not.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •