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

Boolean Parameters (Flag Arguments Smell)

style Beginner

Also Known As

boolean flag parameter flag argument bool param smell

TL;DR

A boolean parameter that switches a function between two different behaviours — a sign the function should be split into two.

Explanation

Martin Fowler calls boolean parameters (flag arguments) a smell because they advertise that the function does two different things. A call like sendEmail($user, true) tells the reader nothing; sendEmail($user, $sendCopy=true) is marginally better but still bifurcates the function. The remedy is to split into two clearly-named functions: sendEmail($user) and sendEmailWithCopy($user), or use an enum/value object to express the mode explicitly. Named arguments (PHP 8.0) mitigate the readability problem but don't fix the underlying design issue.

Common Misconception

A boolean parameter is always cleaner than two separate methods. A boolean flag in a method signature forces callers to pass true/false with no context — render(true) is meaningless at the call site. Two named methods (renderFull, renderSummary) are self-documenting and easier to extend independently.

Why It Matters

Boolean parameters hide meaning at call sites — createUser('Alice', true) tells you nothing; createUser('Alice', sendWelcomeEmail: true) does, and two methods is often cleaner still.

Common Mistakes

  • Multiple boolean parameters: render($template, true, false, true) — impossible to read at call site.
  • Using a boolean to switch between two fundamentally different behaviours — create two methods instead.
  • Not using named arguments (PHP 8) to document boolean flags at call sites.
  • Booleans that change over time to tri-state (null/false/true) — use an enum instead.

Code Examples

✗ Vulnerable
function createUser(string $name, bool $isAdmin): User { ... }
✓ Fixed
function createUser(string $name): User { ... }
function createAdminUser(string $name): User { ... }

Added 15 Mar 2026
Edited 22 Mar 2026
Views 19
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 7 Perplexity 4 Google 2 Unknown AI 2 Ahrefs 1
crawler 15 crawler_json 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Replace boolean flag parameters with two distinct methods or an enum — sendEmail($user, true) becomes sendEmailWithAttachment($user) or sendEmailPlain($user)
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Function with bool $flag parameter controlling entirely different behaviour; call site: doSomething(true) with no context what true means
Auto-detectable: ✗ No phpstan phpcs
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: Function Tests: Update

✓ schema.org compliant