1.2.294. Could Use Existing Constant

This rule reports literals that have the same value as a constant, and, as such, might be used as a constant, instead of a literal.

Floats are not considered by this rule, for comparison reasons. Also, true, false, null, 0 and 1 are also automatically excluded.

<?php

const A = 1;

$a = 1;

?>

Name

Default

Type

Description

omittedValues

array

Comma-separated list of values that have to be ignored with this analysis. They replace the default values of 0 and 1.

1.2.294.1. Connex PHP features

1.2.294.1.1. Suggestions

  • Use the constant instead of the literal

  • Create a new constant for that literal

1.2.294.1.2. Specs

Short name

Constants/CouldUseConstant

Rulesets

All, Changed Behavior, Suggestions

Exakat since

2.3.5

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Medium

Available in

Entreprise Edition, Exakat Cloud