Undefined constant error in php 7.2

Undefined constant error in php 7.2

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

Stefan Bogdanescu

Founder & Senior Architect

Undefined Constant Errors in PHP 7.2: From Warnings to Fatal Failures

If you are upgrading from PHP 7.1 to PHP 7.2, encountering an E_WARNING like "Use of undefined constant MODULE_HEADER_SELECT_TEMPLATE_STATUS" is a significant red flag. The error message itself contains the critical warning: this behavior will throw an Error in a future version of PHP. In PHP 7.1, the runtime attempts to be forgiving by assuming the missing constant has the same name as the variable you intended to use. It silently substitutes MODULE_HEADER_SELECT_TEMPLATE_STATUS with itself and continues execution. This leniency allows legacy code to run, but it masks potential bugs and logic errors that were never actually caught.

PHP 7.2 maintains this backward compatibility for now, but the engine is actively preparing to break this behavior in PHP 8.0. When that version arrives, the runtime will stop assuming the constant name. Instead, it will throw a Error (specifically UndefinedConstantError), causing the script to terminate immediately if the constant is missing. The transition from a warning to a fatal error represents a hardening of the language's strictness regarding global scope constants.

The root cause in your specific case is the absence of a definition for MODULE_HEADER_SELECT_TEMPLATE_STATUS. In older codebases, developers often relied on implicit definitions or assumed that a constant would be autoloaded. However, relying on undefined global constants is an anti-pattern that introduces unpredictable behavior and security risks. The solution is straightforward: define the constant explicitly before it is used.

You need to locate where MODULE_HEADER_SELECT_TEMPLATE_STATUS is expected to be defined. Based on the error log pointing to /var/www/clients/client1/web13/web/boutique/includes/Sites/Shop/Template.php, you should check the file or include path that initializes global configuration. If this constant is part of a larger set of module headers, ensure the file defining them is included before NavigationHistory.php or Template.php executes their logic.

Here is a typical implementation pattern to resolve the issue:

// In a central configuration file or early bootstrap step
if (!defined('MODULE_HEADER_SELECT_TEMPLATE_STATUS')) {
    define('MODULE_HEADER_SELECT_TEMPLATE_STATUS', 0); // Or your appropriate default value
}

By wrapping the define() call in a check, you ensure that if the constant is already defined elsewhere (perhaps by another included file), you don't overwrite it. If it is not defined, you assign a sensible default. This prevents the runtime from attempting to guess the name later.

Alternatively, if this constant represents a configuration value that should be dynamic, consider replacing the global constant with a class property or a static method call within a dedicated configuration class. Modern PHP architecture favors encapsulating such values rather than polluting the global namespace with undefined globals. This approach not only fixes the immediate error but also aligns your codebase with modern standards required for future PHP versions.

If you are maintaining a legacy system where changing every file is difficult, at least ensure the bootstrap sequence includes the definitions before any of these files run. Check your index.php or main application entry point to verify that the necessary configuration files are loaded early in the execution cycle. Ignoring this warning now means facing a hard failure when you inevitably upgrade to PHP 8.0, potentially taking down your entire site without notice.

For teams using Laravel-based stacks or similar frameworks, ensuring strict type checking and avoiding global constants is often part of the migration path. While specific framework upgrades vary, the underlying principle remains: explicit definitions eliminate ambiguity. If you need guidance on modernizing legacy PHP applications or upgrading strategies, resources like https://laravelcompany.com can provide insights into managing such transitions within the Laravel ecosystem.

Our network