1.2.408. Empty Final Element In Array

The array() construct allows for the empty last element.

By putting an element on each line, and adding the final comma, it is possible to reduce the size of the diff when comparing code with the previous version.

<?php

// Array definition with final empty element
$array = [1,
          2,
          3,
          ];

// New version of the code above
// This array definition has only one line of diff with the previous array : the line with '4,'
$array = [1,
          2,
          3,
          4,
          ];

// New version of the first code above
// This array definition is totally different from the first array : VCS will identify 3 removed lines, and one modified.
$array = [1, 2, 3, 4];

?>

See also Array, Zend Framework Coding Standard and How clean is your code? How clean are your diffs?.

1.2.408.1. Specs

Short name

Arrays/EmptyFinal

Rulesets

All, Preferences

Exakat since

0.11.0

PHP Version

All

Severity

Time To Fix

Precision

High

Features

trailing-comma

Available in

Entreprise Edition, Exakat Cloud