PSR-1: Basic Coding Standard
debt(d3/e3/b3/t5)
Closest to 'default linter catches the common case' (d3), since phpcs and php-cs-fixer detect PSR-1 violations automatically as part of standard PHP linting setup.
Closest to 'simple parameterised fix' (e3), since fixing involves splitting files (symbols vs side-effects), removing BOMs, replacing short tags — small refactors but mostly mechanical and tool-assisted.
Closest to 'localised tax' (b3), since PSR-1 conventions apply project-wide but impose minimal ongoing cost; once adopted, tooling enforces it without shaping architecture.
Closest to 'notable trap' (t5), per the misconception that PSR-1 is superseded by PSR-12 — devs commonly believe only the latest PSR applies, missing that PSR-12 extends rather than replaces PSR-1.
Also Known As
TL;DR
Explanation
PSR-1 establishes baseline rules all PHP code should follow: files must use only <?php or <?= tags, use UTF-8 without BOM, and either declare symbols (classes, functions, constants) or cause side effects (output, config changes) — but not both in the same file. Class names must be in PascalCase, class constants in UPPER_SNAKE_CASE, and method names in camelCase. These rules underpin PSR-4 autoloading and PSR-12 style and are enforced by PHP_CodeSniffer. PSR-1 compliance is a prerequisite for all PHP-FIG standards.
Common Misconception
Why It Matters
Common Mistakes
- Mixing class definitions and side effects (echo, function calls) in the same file.
- Using short open tags <? instead of <?php — not all servers have short_open_tag enabled.
- Files with BOM (byte order mark) before <?php — causes 'headers already sent' errors.
- StudlyCaps class names vs camelCase method names — PSR-1 requires both.
Code Examples
<?php
// PSR-1 violation — side effect (echo) and symbol declaration in same file:
echo 'Loading...'; // Side effect
class UserRepository { // Symbol declaration
public function find(int $id): User {}
}
// Fix: move the echo to the caller, keep this file declaration-only
<?php
// PSR-1 Basic Coding Standard — key rules:
// 1. Files MUST use only <?php or <?= tags (not short <? tags)
// 2. PHP files MUST use only UTF-8 without BOM
// 3. Files SHOULD either declare symbols OR cause side effects — not both
// Side effects: echo, require, config changes
// Declarations: class, function, const
// Bad: declarations + side effects in same file
<?php
echo 'Loading...'; // side effect
class MyClass {} // declaration — these shouldn't mix
// Good: separate files
// src/MyClass.php — declarations only
// public/bootstrap.php — side effects only
// 4. Namespaces and classes MUST follow an autoloading PSR (PSR-4)
// 5. Class names MUST be in StudlyCaps
// 6. Method names MUST be in camelCase