---
title: Boolean Names Is/Has/Should
impact: HIGH
impactDescription: makes conditions instantly readable
tags: naming, booleans, readability, quality, php
---

## Boolean Names Is/Has/Should

Boolean variables and methods should use prefixes like `is`, `has`, `should`, `can`, or `will`. This makes conditions and logic flows instantly readable and distinguishes booleans from other data types.

**Incorrect (unclear boolean names):**

```php
$active = ($user->status === 'active');
$admin = checkAdminRole($user);
$items = (count($cart) > 0);
$refresh = needsRefresh();

if ($active) { ... } // Unclear if $active is an object, string, or boolean
```

**Correct (boolean prefixes):**

```php
$isActive = ($user->status === 'active');
$isAdmin = checkAdminRole($user);
$hasItems = (count($cart) > 0);
$shouldRefresh = needsRefresh();
$canEdit = hasPermission($user, 'edit');

if ($isActive) { ... } // Instantly readable context
```

**Common Boolean prefixes:**

| Prefix | Use Case | Example |
|--------|----------|---------|
| `is` | State or identity | `$isEnabled`, `$isActive`, `$isOwner` |
| `has` | Possession or existence | `$hasPermission`, `$hasErrors`, `$hasAttachment` |
| `should` | Boolean logic for decisions | `$shouldRetry`, `$shouldRedirect`, `$shouldSave` |
| `can` | Permissions or capabilities | `$canDelete`, `$canViewAdmin`, `$canUpload` |
| `will` | Future state or intent | `$willExpire`, `$willAutoRenew` |

**Best Practice for Methods:**
Always prefer naming boolean-returning methods with these prefixes as well:
```php
public function isActive(): bool { ... }
public function hasPermission(string $perm): bool { ... }
```

**Tools:** PHPStan (check-naming-conventions), PR review
