Undefined constant “%s

Description

The requested constant doesn’t exist.

The constant may be defined at different places in the code :

  • In the running code: it could be in a different file, which was not included yet, or later in the code.

  • In a dependency: use the name of the constant to find which dependency defines this constant. Then, make sure the dependency is satisfied.

  • In an extension: use the name of the constant to find which PHP extension defines this constant. For example, XML_PI_NODE is from the ext/xml extension, which may not be in the current PHP engine.

There is a distinct message for class constants.

Example

<?php

// early usage of the constant
echo A;

const A = 2;

?>

Literal Examples

  • Undefined constant “A”

  • Undefined constant “XML_PI_NODE”

Solutions

  • Find the actual name of the requested constant.

  • Check the namespace, or its import: use const.

  • Check if the constant is used after its definition.

  • Check if the constant is defined in a PHP extension, and the extension was forgotten.

  • Check if the constant is defined in a dependency, and the dependency was forgotten.