1.2.748. Multiply By One¶
Multiplying by 1 is a fancy type cast.
If it is used to type cast a value to number, then casting (int) or (float) is clearer. This behavior may change with PHP 7.1, which has unified the behavior of all hidden casts.
<?php
// Still the same value than $m, but now cast to integer or float
$m = $m * 1;
// Still the same value than $m, but now cast to integer or float
$n *= 1;
// make typecasting clear, and merge it with the producing call.
$n = (int) $n;
?>
See also Type Juggling.
1.2.748.1. Connex PHP features¶
1.2.748.1.1. Suggestions¶
Typecast to (int) or (float) for better readability
Skip useless math operation altogether
1.2.748.1.2. Specs¶
Short name |
Structures/MultiplyByOne |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
High |
ClearPHP |
|
Examples |
|
Available in |