Missing Function Comments
Also Known As
missing PHPDoc method
undocumented function
no method comment
TL;DR
Functions without PHPDoc lose IDE parameter hints, inline documentation, and the opportunity to explain non-obvious behaviour, preconditions, and edge cases.
Explanation
In PHP 8 with full native type declarations, @param and @return are often redundant — the types speak for themselves. What is never redundant: a one-line summary of what the function does, @throws documentation for every exception that can propagate out, @deprecated for functions being phased out, and explanatory notes for any non-obvious preconditions or side effects. PHPStan and Psalm use PHPDoc for complex generics and templates that native types cannot express.
Common Misconception
✗ Native PHP 8 type declarations make PHPDoc obsolete — @throws, complex generics (array<string, User>), and explanatory summaries cannot be expressed with native types alone.
Why It Matters
Missing @throws documentation means callers do not know they must handle an exception — undocumented exceptions cause unhandled exception crashes in production.
Common Mistakes
- Omitting @throws for every exception that can escape the function.
- Repeating the method name as the docblock: /** getUserById */ — adds nothing.
- Not documenting preconditions: the caller must ensure X before calling this.
- Outdated docblocks after parameter types changed — wrong documentation is worse than none.
Code Examples
✗ Vulnerable
// No docblock — what does it throw? What are the constraints?
public function transfer(int $fromId, int $toId, float $amount)
{
if ($amount <= 0) throw new InvalidArgumentException('Amount must be positive');
// Can throw DatabaseException, InsufficientFundsException...
$this->db->beginTransaction();
// ...
}
✓ Fixed
/**
* Transfers funds between two accounts atomically.
*
* @param int $fromId Source account ID
* @param int $toId Destination account ID
* @param float $amount Positive amount in account currency
*
* @throws InvalidArgumentException If amount is not positive
* @throws InsufficientFundsException If source balance is insufficient
* @throws DatabaseException On transaction failure (rolled back)
*/
public function transfer(int $fromId, int $toId, float $amount): void
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
20
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 8
Perplexity 4
Google 2
Ahrefs 2
How they use it
crawler 15
crawler_json 1
Related categories
⚡
DEV INTEL
Tools & Severity
🟢 Low
⚙ Fix effort: Low
⚡ Quick Fix
Add PHPDoc only when the method signature doesn't tell the whole story — complex @param types, @throws, or a non-obvious @return are valuable; don't duplicate what type declarations already express
📦 Applies To
PHP 5.0+
web
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
Public method with complex array shape return type undocumented; @throws not documented; method with non-obvious side effects undocumented
Auto-detectable:
✓ Yes
phpcs
phpstan
phpmd
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Medium
✗ Manual fix
Fix: Low
Context: Function