SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2010
    Posts
    197
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    error reporting on in PHP code vs. ini file

    right now i'm in development. most sources i read recommend controlling error reporting with code like this in a config file:

    Code PHP:
    if(DEBUG == true)
    {
        ini_set('display_errors', 'On');
        error_reporting(E_ALL);
    }
    else
    {
        ini_set('display_errors', 'Off');
        error_reporting(0);
    }

    but why wouldn't I just update the ini file to match the error reporting i wanted? is there an advantage of one way over the other?

    Thanks

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by sessions View Post
    right now i'm in development. most sources i read recommend controlling error reporting with code like this in a config file:

    Code PHP:
    if(DEBUG == true)
    {
        ini_set('display_errors', 'On');
        error_reporting(E_ALL);
    }
    else
    {
        ini_set('display_errors', 'Off');
        error_reporting(0);
    }

    but why wouldn't I just update the ini file to match the error reporting i wanted? is there an advantage of one way over the other?

    Thanks
    Generally so that you are not affecting other projects that may reside on the same server (using the same config file).

    Side note and sort of self promotion, have a look at https://github.com/KyleWolfe/PHPErrorNet. A controversial topic, but like it or not, PHP is far looser than other languages. I recommend tightening it up, and force yourself to write better code. This project also gives you an easy way to have centralized reporting on those exceptions / errors (email, logging, etc)
    Last edited by K. Wolfe; Apr 24, 2014 at 09:44. Reason: Grammer


Bookmarks

Posting Permissions

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