1.2.744. 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.744.1. Suggestions

  • Typecast to (int) or (float) for better readability

  • Skip useless math operation altogether

1.2.744.2. Specs

Short name

Structures/MultiplyByOne

Rulesets

All, Analyze, CE, CI-checks, Rector

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

High

Features

neutral-element

ClearPHP

no-useless-math

Examples

SugarCrm, Edusoho

Available in

Entreprise Edition, Community Edition, Exakat Cloud