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

Boolean Parameters (Flag Arguments Smell)

Style Beginner
debt(d6/e3/b3/t5)
d6 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5), +1. While phpstan and phpcs are listed as detection tools, the detection_hints explicitly say automated: no. These tools can flag boolean parameters in some cases (e.g. custom phpcs sniffs), but reliably detecting when a boolean flag is a genuine smell vs. acceptable usage requires code review judgment. Falls between specialist tooling and careful code review.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix says to replace a boolean flag parameter with two distinct methods or an enum. This is a straightforward refactor — rename/split the method and update call sites — but it typically touches more than one line since callers must be updated too. Still localised to one method and its callers, so e3 fits.

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

Closest to 'localised tax' (b3). Boolean parameters are a per-method/per-API concern. They make individual call sites harder to read and the method harder to extend, but they don't impose a system-wide architectural constraint. The smell is localised — each instance can be fixed independently without cross-cutting impact. Applies across web/cli/queue contexts but each instance is self-contained.

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

Closest to 'notable trap' (t5). The misconception states that 'a boolean parameter is always cleaner than two separate methods' — this is a well-documented gotcha that most developers eventually learn but initially get wrong. Many competent developers coming from other paradigms default to boolean flags thinking they reduce code duplication, not realizing they sacrifice readability at call sites. The tri-state evolution pitfall (bool becoming null/false/true) adds another documented surprise.

About DEBT scoring →

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 41
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 1 ping S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 1 ping S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Amazonbot 8 Perplexity 4 Ahrefs 4 Scrapy 4 SEMrush 3 Google 2 Unknown AI 2 Claude 1 Bing 1 Meta AI 1 Yandex 1 PetalBot 1
crawler 30 crawler_json 2
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