How do I turn off PHP Notices?

How do I turn off PHP Notices?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How do I turn off PHP Notices?

When you see a browser output like Notice: Constant DIR_FS_CATALOG already defined, it signals that your application is executing code in an order that violates PHP's expectations. You might assume this is purely a presentation issue and think disabling error reporting will hide the message. However, simply setting display_errors = Off in your php.ini file often fails to suppress these notices if you haven't addressed the underlying logic or the execution environment correctly.

The core misunderstanding here is confusing displaying errors with reporting them. The display_errors directive controls whether PHP sends error messages directly to the browser output stream. Disabling it hides the message from the user but does not stop PHP from generating the log entry or, more importantly, does not suppress the notice if the application code is actively configured to catch and echo these specific exceptions.

In many legacy applications, particularly those built with older frameworks or custom scripts, there is a common pattern where developers wrap their core logic in a generic error handler that explicitly checks for E_NOTICE levels and prints them anyway. If you have a line of code somewhere resembling echo error_get_last() or a custom function that logs all notices to the screen, turning off display_errors will not bypass that logic. You must locate and modify the code that is intentionally echoing these messages.

Furthermore, the specific error Constant DIR_FS_CATALOG already defined suggests a conflict in your include paths. This typically happens when an autoloader or a configuration file attempts to define a constant before the main application entry point has had a chance to initialize it properly. In PHP 5.3 and earlier, the behavior of notices was lenient; they were treated as warnings rather than fatal errors. If you are running on PHP 5.3, you may be seeing a "Call Stack" in your logs because the environment is designed to treat these definitions as non-fatal but significant enough to warrant a trace. Upgrading to PHP 5.4 or higher generally changed how notices were handled, treating them closer to warnings, which can alter how your logging system captures them.

If you are deploying on a shared hosting environment where you cannot modify php.ini, the standard approach is to use .htaccess to override these settings. You can add display_errors = 0 and error_reporting = E_ALL & ~E_NOTICE to your .htaccess file. However, this still only affects what the browser sees; it does not fix the logic error causing the constant to be redefined.

The most robust solution involves inspecting your autoloading mechanism. If you are using a class loader or an autoloader that tries to define constants dynamically, ensure it checks if the constant exists before defining it. You can wrap the definition in a conditional check:

if (!defined('DIR_FS_CATALOG')) {
    define('DIR_FS_CATALOG', '/path/to/catalog');
}

This pattern prevents the "already defined" notice regardless of the order in which files are included. If you cannot modify the source code immediately, you may need to adjust your include stack to ensure the main configuration file runs before any other scripts attempt to define these constants.

Ignoring these notices is generally a bad practice. While they do not stop script execution like fatal errors do, they indicate that your application's state management is inconsistent. Relying on display_errors = Off without fixing the code path leads to silent failures where debugging becomes impossible because the logs are cluttered with noise you cannot distinguish from actual logic errors. If you are building a new stack or refactoring an existing one, consider migrating to modern PHP versions where strict types and error handling make these inconsistencies much harder to miss.

Our network