1.2.218. Const Or Define Preference

Const and define() have almost the same functional use : they create constants.

The analyzed code has less than 10% of one of them : for consistency reasons, it is recommended to make constant definition consistent.

It is recommended to use const for global constants, as this keyword is processed at compile time, while define() is executed.

Note that define() used to allow the creation of case-insensitive constants, but this is deprecated since PHP 7.3 and will be removed in PHP 8.0.

<?php

    define('A1', 1);
    define('A2', 1);
    define('A3', 1);
    define('A4', 1);
    define('A5', 1);
    define('A6', 1);
    define('A7', 1);
    define('A8', 1);
    define('A9', 1);
    define('A10',1);

    const B = 3;

?>

See also Constant definition and Define.

1.2.218.1. Specs

Short name

Constants/ConstDefinePreference

Rulesets

All, Changed Behavior, Preferences

Exakat since

1.3.9

PHP Version

All

Severity

Time To Fix

Precision

Very high

Features

define, const, constant

Available in

Entreprise Edition, Exakat Cloud