Menu

← Back to whitespace.*

Error Identifier: whitespace.fileEnd

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

namespace App;

echo 'foo';

?>

The file above ends with a closing ?> tag followed by trailing whitespace.

Why is it reported? #

When a PHP file ends with a closing ?> tag followed by whitespace (spaces, tabs, or newlines), that whitespace is treated as output by the web server. This can cause “headers already sent” errors when the code tries to set HTTP headers, start sessions, or perform redirects. It can also cause unexpected output in included files.

How to fix it #

The recommended approach is to remove the closing ?> tag entirely. The PHP manual recommends omitting the closing tag in files that contain only PHP code:

 <?php declare(strict_types = 1);
 
 namespace App;

 echo 'foo';
-
-?>
-

If the closing ?> tag must be kept, remove any whitespace after it so the file ends immediately after the ?>:

 <?php declare(strict_types = 1);
 
 namespace App;

 echo 'foo';

 ?>
-

How to ignore this error #

You can use the identifier whitespace.fileEnd to ignore this error using a comment:

// @phpstan-ignore whitespace.fileEnd
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: whitespace.fileEnd

Rules that report this error #

  • PHPStan\Rules\Whitespace\FileWhitespaceRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.