1.2.449. Favorite Casting Method¶
There are two methods for casting : the cast operators, or the conversion functions. The cast operators are int
, float
and string
. The conversion functions are intval()
, floatval()
and strval()
.
The analyzed code has less than 10% of one of them : for consistency reasons, it is recommended to make them all the same.
It happens that casting operators or conversion functions are used depending on coding style and files.
<?php
// be consistent
$a = (int) $_GET['a'];
$b = (float) $_GET['b'];
$c = (int) $_GET['c'];
$d = (int) $_GET['d'];
$e = (string) $_GET['e'];
$f = (int) $_GET['f'];
$g = (int) $_GET['g'];
$i = (int) $_GET['i'];
$j = (int) $_GET['j'];
$k = (int) $_GET['k'];
$l = intval($_GET['l']);
?>
1.2.449.1. Connex PHP features¶
1.2.449.1.1. Suggestions¶
Choose one of the two syntaxes
1.2.449.1.2. Specs¶
Short name |
Structures/CastFavorite |
Rulesets |
|
Exakat since |
2.6.1 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |