views:

175

answers:

7
Notice: Constant DIR_FS_CATALOG already defined

I've already commented out display_errors in php.ini,but is not working.

How do I make PHP not output such things to browsers?

UPDATE

I put display_errors = Off there but it's still reporting such notices,

is this an issue with PHP5.3?

Reporting numerous Call Stack too..

+8  A: 

You can set display_errors to 0 or use the error_reporting() function.

However, notices are annoying (I can partly sympathize) but they serve a purpose. You shouldn't be defining a constant twice, the second time won't work and the constant will remain unchanged!

Pekka
+1: I approve of mentioning that he should correct the errors, not turn off the reporting. And you did it in a gentler way than @Jonathan Kuhn :-)
Josh
No,seems this is a bug of php5.3,`display_errors` doesn't work as expected.
@user can you show the php.ini entry please?
Pekka
`display_errors = Off` is already there.
@user try a `phpinfo()` to see whether the setting actually applies. Forgive me, but I strongly doubt that you have found a bug in PHP 5.3 - I will only believe it when I see it :)
Pekka
Strange,the `local value` is On,but the `master value` is off,don't know what that means exactly...
@user do you have a `error_reporting()` command somewhere that overrides the ini setting?
Pekka
I've commented those commands.Besides,`error_reporting` and `display_errors` are two different directive,IMO.It should have something to do with `local value`,investigating..
@user I meant `ini_set("display_errors")`, sorry.
Pekka
Tried,not working.Do you know what does `local value/master value` mean for `display_errors` in `phpinfo()` ?
@user I think the local value can come from `ini_set` directives or `php_ini_flag` settings in `.htaccess` files.
Pekka
Bingo!!!I want to mark your comment as accepted 100 times! It's in `.htaccess`,never know that ,I only know apache deals with that file,how can it also affect PHP,strange...
@user ha! That was unexpected. Glad it got sorted out.
Pekka
+1  A: 

From the PHP documentation (error_reporting):

<?php
// Turn off all error reporting
error_reporting(0);
?>

Other interesting options for that function:

<?php

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>
Cristian
A: 

You can set ini_set('display_errors',0); in your script or define which errors you do want to display with error_reporting().

jeroen
A: 

by not causing the errors:

defined('DIR_FS_CATALOG') || define('DIR_FS_CATALOG', 'whatever');

If you really have to, then change error reporting using error_reporting() to E_ALL^E_NOTICE.

Jonathan Kuhn
If it's a production site, whether or not you think it's error-free, you should still not display errors if they arise - so 'by not causing the errors' seems like a bit of a cheeky response to a valid question.
Cam
since when is it ok to allow errors in a production site? I agree that on a production site you shouldn't display errors, that's not what I was saying. I was saying that you should check if the constant is defined and set it if not (which is why I gave the code sample).
Jonathan Kuhn
A: 

You can check if the constant's already defined using:

<?php
if (!defined('MYCONST'))
    define('MYCONST', 'Weeha!');
?>
TiuTalk
A: 

I believe commenting out display_errors in php.ini won't work because the default is On. You must set it to 'Off' instead.

Don't forget to restart Apache to apply configuration changes.

Also note that while you can set display_errors at runtime, changing it here does not affect FATAL errors.

As noted by others, ideally during development you should run with error_reporting at the highest level possible and display_errors enabled. While annoying when you first start out, these errors, warnings, notices and strict coding advice all add up and enable you to becoem a better coder.

AllenJB
A: 

I found this trick out recently. Whack an @ at the start of a line that may produce an warning/error.

As if by magic, they dissapear.

DrLazer
thats a poor idea usually, its like putting in earplugs because your car is making a horrible grinding noise.
David Morrow