1.2.1342. Use The Blind Var

When in a loop, it is faster to rely on the blind var, rather than the original source.

When the key is referenced in the foreach loop, it is faster to use the available container to access a value for reading.

Note that it is also faster to use the value with a reference to handle the writings.

<?php

// Reaching $source[$key] via $value is faster
foreach($source as $key => $value) {
    $coordinates = array('x' => $value[0],
                         'y' => $value[1]);
}

// Reaching $source[$key] via $source is slow
foreach($source as $key => $value) {
    $coordinates = array('x' => $source[$key][0],
                         'y' => $source[$key][1]);
}

?>

1.2.1342.1. Suggestions

  • Use the blind var

1.2.1342.2. Specs

Short name

Performances/UseBlindVar

Rulesets

All, Changed Behavior, Performances

Exakat since

1.2.9

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Features

blind-variable

Available in

Entreprise Edition, Exakat Cloud