← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

PHPDoc / Docblock

Style PHP 5.0+ Beginner
debt(d3/e1/b3/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). The term's detection_hints.tools lists phpstan, psalm, phpcs, and phpdoc — these are standard PHP ecosystem tools that catch redundant docblocks, missing @throws tags, and type mismatches. PHPStan and Psalm are commonly configured in CI pipelines and flag docblock issues automatically.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix describes adding or removing docblock annotations — this is a single-line or few-line change per method. Fixing outdated docblocks or adding missing @throws is localized to the declaration site with no ripple effects.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). Docblock conventions apply across all PHP contexts (web, cli, queue-worker per applies_to), but the impact is localized — poor docblock hygiene affects IDE autocompletion and static analysis accuracy for that component, not architectural decisions. It's a persistent minor friction rather than a system-shaping choice.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field states developers believe 'PHPDoc blocks are redundant once PHP has native type declarations' — this is a documented gotcha that most PHP devs eventually learn. The trap is that docblocks serve purposes native types cannot (generics via @template, exception contracts via @throws, complex array shapes), but it's not counterintuitive once explained.

About DEBT scoring →

Also Known As

PHPDoc block PHP docblock doc comment

TL;DR

Structured comment blocks that document functions, classes, and properties — read by IDEs, static analysis tools, and documentation generators.

Explanation

PHPDoc docblocks (/** ... */) use tags like @param, @return, @throws, @var, @property, @template, and @deprecated to annotate code. IDEs (PhpStorm, VS Code with Intelephense) use them for autocomplete and type inference; tools like PHPStan and Psalm use them for advanced static analysis; phpDocumentor generates API documentation from them. With modern PHP's native type declarations, many @param and @return tags are redundant — use them to add context, describe array shapes, or document generic types not expressible in PHP's type system.

Common Misconception

PHPDoc blocks are redundant once PHP has native type declarations. Docblocks add information native types cannot express — @throws for exception contracts, @template for generics, complex union types in PHP 7, and @var for inline variable annotation used by IDEs and static analysers.

Why It Matters

PHPDoc docblocks provide machine-readable type information and documentation — IDEs use them for autocompletion, static analysers use them for type inference, and developers use them for understanding intent.

Common Mistakes

  • Docblocks that restate the type declarations already visible in the signature — zero added value.
  • Missing @throws tags — callers cannot know which exceptions to handle.
  • @param with no description for non-obvious parameters — the type is already in the declaration.
  • Outdated docblocks that contradict the current code — worse than no docblock.

Code Examples

💡 Note
Only document what types can't express: thrown exceptions, pre/post-conditions, non-obvious behaviour. Don't restate the signature.
✗ Vulnerable
/**
 * Get user
 * @param int $id The id
 * @return User The user
 */
public function getUser(int $id): User // Docblock adds nothing — all visible in signature

// Valuable docblock:
/**
 * Finds user by ID. Throws if not found because callers must handle absence explicitly.
 * @throws UserNotFoundException if no user with this ID exists
 * @throws DatabaseException on connection failure
 */
✓ Fixed
/**
 * Transfer funds between two accounts atomically.
 *
 * @param  Account $from      Source account — must have sufficient balance
 * @param  Account $to        Destination account
 * @param  Money   $amount    Amount to transfer — must be positive
 * @return Transfer           The completed transfer record
 * @throws InsufficientFundsException  If $from balance < $amount
 * @throws CurrencyMismatchException   If accounts use different currencies
 */
public function transfer(Account $from, Account $to, Money $amount): Transfer

// Skip docblocks when types + names are already self-documenting:
public function findById(int $id): ?User {} // no docblock needed

Added 15 Mar 2026
Edited 22 Mar 2026
Views 60
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 3 pings F 2 pings S 3 pings S 1 ping M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 10 Perplexity 9 Amazonbot 9 Ahrefs 5 SEMrush 5 Unknown AI 3 Google 2 Claude 2 Bing 2 Majestic 1 Meta AI 1
crawler 46 crawler_json 2 pre-tracking 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Use PHPDoc @param, @return, @throws for complex types that PHP's native type system cannot express — for simple scalar types, prefer native type declarations over redundant docblocks
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
@param string $name on method with string $name native type — redundant; missing @template for generic types; @return array when array{id: int, name: string} would be precise
Auto-detectable: ✓ Yes phpstan psalm phpcs phpdoc
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Low Context: Function


✓ schema.org compliant