Search code examples
phperror-reporting

Is it considered standard practice to turn off notices in the error log for PHP development


I coming from a J2EE background and it seems that it is very common for PHP developers to turn off and ignore notices with the statement: error_reporting(E_ALL & ~E_NOTICE);

The application that I'm working is full of messages about unset variables? This seems very odd to me.


Solution

  • It's bad practise, but it's pretty common.

    You could say it's considered standard practise since it's the default setting out of the box.

    However the fact that it's the default setting in PHP shouldn't be taken as meaning it's a good idea! (cough register_globals cough)

    The problem is that E_NOTICE covers both undefined variable and undefined array indexes, the former of which is a far better indication of a bug than the latter.

    The classic bug that this hides is using $var when you meant to use $this->var. For this reason alone I think it's worth being anal about cleaning up the undefined array index warning messages so that undefined variable bugs are more obvious.

    I had thought that PHP 5.3 allowed you to separate these (I'm not using it yet), but I've just looked and I can't find mention of this.