1.2.1244. Undefined Constants

Constants definition can’t be located.

Those constants are not defined in the code, and will raise errors, or use the fallback mechanism of being treated like a string. It is recommended to define them all, or to avoid using them.

<?php

const A = 1;
define('B', 2);

// here, C is not defined in the code and is reported
echo A.B.C;

?>

See also Constants.

1.2.1244.1. Suggestions

  • Define the constant

  • Fix the name of the constant

  • Fix the namespace of the constant (Fully Qualified Name or use)

  • Remove the usage of the constant

1.2.1244.2. Specs

Short name

Constants/UndefinedConstants

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior, CompatibilityPHP72

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

typo

Related rule

Constant Typo Looks Like A Variable

Available in

Entreprise Edition, Community Edition, Exakat Cloud