1.2.1327. Use Constant As Arguments¶
Some methods and functions are defined to be used with constants as arguments. Those constants are made to be meaningful and readable, keeping the code maintenable. It is recommended to use such constants as soon as they are documented. Here is the list of functions that use a unique PHP constant as argument :
Here is the list of functions that use a combination of PHP native constants as argument.
runkit_import()
<?php
// Turn off all error reporting
// 0 and -1 are accepted
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// The first argument can be one of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
$search_html = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
// sort accepts one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_LOCALE_STRING, SORT_NATURAL
// SORT_FLAG_CASE may be added, and combined with SORT_STRING or SORT_NATURAL
sort($fruits);
?>
1.2.1327.1. Suggestions¶
Use PHP native constants, whenever possible, instead of nondescript literals.
1.2.1327.2. Specs¶
Short name |
Functions/UseConstantAsArguments |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Examples |
|
Available in |