phanalist

E0001: Opening Tag Position

In plain English: The PHP opening tag (<?php) should always be placed on the very first line of the file, starting at column 1.

Why it matters: If there is any whitespace, blank lines, or HTML output before <?php, PHP will immediately send headers and output to the browser. This can cause unexpected whitespace in JSON/API responses, “Headers already sent” warnings, or break redirects and cookies.

❌ The Bad Example


<?php
// There is an empty blank line before the opening tag!
echo "Hello World";

✅ The Good Example

<?php
declare(strict_types=1);

namespace App;

echo "Hello World";

(Note: Shebang lines like #!/usr/bin/env php for CLI scripts are allowed on the very first line before <?php).

What the rule checks

When it does not report

How to fix

Configuration

E0001 has no configuration options and is enabled by default.

Junior Engineer’s Rule of Thumb:

Always make <?php the absolute first characters in your PHP source files (unless writing a CLI script with a shebang). Never leave blank lines at the top of your files!