1.2.478. Forgotten Whitespace

Forgotten whitespaces brings unexpected error messages.

White spaces have been left at either end of a file : before the PHP opening tag, or after the closing tag.

Usually, such whitespaces are forgotten, and may end up summoning the infamous ‘headers already sent’ error. It is better to remove them.

<?php
    // This script has no forgotten whitespace, not at the beginning
    function foo() {}

    // This script has no forgotten whitespace, not at the end
?>

See also How to fix Headers already sent error in PHP.

1.2.478.1. Suggestions

  • Remove all whitespaces before and after a script. This doesn’t apply to template, which may need to use those spaces.

  • Remove the final tag, to prevent any whitespace to be forgotten at the end of the file. This doesn’t apply to the opening PHP tag, which is always necessary.

1.2.478.2. Specs

Short name

Structures/ForgottenWhiteSpace

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

High

Features

whitespace

Available in

Entreprise Edition, Community Edition, Exakat Cloud