1.2.1105. Should Use Existing Constants

The following functions have related constants that should be used as arguments, instead of scalar literals, such as integers or strings.

<?php

// The file is read and new lines are ignored.
$lines = file('file.txt', FILE_IGNORE_NEW_LINES)

// What is this doing, with 2 ?
$lines = file('file.txt', 2);

?>

See also Bitmask Constant Arguments in PHP.

1.2.1105.1. Suggestions

  • Use PHP native constants whenever possible, for better readability.

1.2.1105.2. Specs

Short name

Functions/ShouldUseConstants

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

predefined-constant, constant

Examples

Tine20

Available in

Entreprise Edition, Exakat Cloud