Skip to content
Comic-style drawing of a control panel: a row of chunky toggle switches under glowing red lights, labeled ON, OFF, OF, OF, and gibberish after that
ON, OFF, OF, OF. Close enough. *

Quick and Dirty Feature Flags

Phillip Harrington Jun 2026

First published on LinkedIn, May 2026.

Comments

TL;DR: Feature flags give your team permission to merge unfinished code, and that's what keeps PRs small. You don't need LaunchDarkly yet. A config file and a five-line helper will carry a small-to-mid team a long way.


I've been ranting about small PRs and breaking down tickets, and I keep saying "put it behind a feature flag" without ever showing how. The strawman in my head has noticed:

"Sure, Phil, but how am I supposed to ship a feature that isn't finished yet? Half-built code goes to prod, users see weird half-rendered junk, on-call gets paged, everybody loses."

Fair point. Here's how, and you don't need LaunchDarkly to do it.

How a PR Gets to 4,000 Lines

Somebody gets a two-week ticket. (We're already off to a bad start.) Half of it doesn't work without the other half, so they don't merge anything until it's all done, and the branch keeps growing. By the end they're rebasing every morning, the PR is 4,000 lines, and the reviewer skims it, because nobody can hold 4,000 lines in their head. Bugs get through, and next sprint it happens again.

Nobody sets out to write that PR. They were being responsible: you don't ship half a feature. Feature flags get them out of that bind.

Merge It Anyway

Merge every day, finished or not, and wrap anything a user could see in a flag check. The flag stays off in production, so nobody sees the half-built thing, and your reviewer gets a steady stream of small PRs instead of one monster. When it's done, flip the flag on. If it breaks, flip it back off.

Quick and Dirty

You don't need a platform for this. A config file and a helper function will get you most of the way. It's disgustingly simple on purpose. (The one I built at work was basically the same thing in a class. More on that later.) Here's the whole thing:

// config/features.php
return [
    'new_billing_flow'    => false,
    'csv_export_v2'       => true,
    'experimental_search' => false,
];
// app/helpers.php
function feature(string $name): bool {
    static $flags = null;
    $flags ??= require __DIR__ . '/../config/features.php';
    return $flags[$name] ?? false;
}

Now, in your code:

if (feature('new_billing_flow')) {
    return $this->renderNewBillingFlow($invoice);
} else {
    return $this->renderLegacyBillingFlow($invoice);
}

Or, in a template:

<div>
    <?php if (feature('team_invites')): ?>
        <a href="/admin/teams/invite">Invite team members.</a>
    <?php endif; ?>
</div>

A Few Rules

  • Default to false. An unknown flag name returns false, so new code stays off until somebody turns it on deliberately. Don't throw an exception. Don't even log it.
  • Name flags after the feature, not the implementation.new_billing_flow ages well. use_redis_tenant_cache_with_double_checked_locking_v2 does not.
  • Plan to delete them. Once a feature is launched, stable and on for everybody, rip out the flag and the old code path. Otherwise your codebase turns into a museum of toggles nobody remembers.

When to Graduate

The config-file version handles more than people expect. It runs out when you need any of these:

  • Per-tenant flags. "Turn this on for ACME Corp, but not for everyone else." A boolean isn't enough. You need a check against the tenant ID, and you probably want it stored somewhere editable.
  • Percentage rollouts. "Show this to 5% of users, then 25%, then 100%." That's a real platform feature.
  • Runtime toggles. Flipping a flag without redeploying. Useful for incident response.
  • Audit trails. Who turned what on, and when. Required in some regulated environments.

If you need any of those, LaunchDarkly, Unleash or a database-backed system of your own will earn its keep. (If you build your own, read From the Trenches first.)

Most teams reach for those tools the way developers reach for Redux: about a year before they need them.

Permission to Merge

The flag is the easy part. What changes things is the permission: your team is allowed to merge code that isn't done. Without it, you'll keep getting 4,000-line PRs no matter how loudly you preach "break it down."

Steve, one of the best dev managers I ever worked with, once told me the difference between a junior team and a senior team is what they're allowed to merge. Junior teams merge finished features in big chunks. Senior teams merge unfinished code on purpose, behind a flag, and turn it on when it's ready.

From the Trenches

At one company, I spent a while fighting for simplicity in a world gone mad. It started with our first feature flags, which I wrote: a Feature class with one method, so code read if ($feature->enabled(Features::NEW_BILLING_FLOW)), with the names in a Features enum. Config only, no database. Only devs touched it, so that was fine. (Told you it wasn't much fancier than the helper.)

Then it grew, one reasonable step at a time. At first:

  • Into a database. A name and an on/off, looked up once per request. Fine.
  • Per tenant. Add a tenant_id column. Great for a few tenants. For 90% of them, it took about 450 rows, and somebody balked.
  • For everyone. That's when you delete the flag, I said. Failing that, one table: a null tenant_id means every tenant, and a few rows set to 0 carve out the holdouts. That nullable column is a little hair, but simple was the point: same interface, slightly different queries.
  • What we built instead. A second table whose enabled_all_tenants overrides the first. Two sources of truth, three counting the enum. The reason: the business wanted a list of every feature. We build web pages for a living, I said, so let's keep the one simple table and make them a page. The two-table plan won out.
  • The overhaul. A later rewrite kept both tables, and the enum, and the override, and added a cache check of its own, and then made an unknown flag throw an exception instead of returning false. That would have meant every flag lives in the database forever, even the ones on for everybody, which, again, should have been deleted. We settled on returning false... but still added the log line.

Woof. Here's what each design costs in rows, with about 500 tenants:

On forPer tenantTwo tables (built)One table (pitched)
A few tenants222
450 of 50045045051
Everyone50011

The second table only helps in the bottom row, the one that should be zero. Rows are cheap, though. Developer hours aren't: the system got rebuilt halfway three times, and every other developer who touched it had to learn two tables, an enum and which one wins.

I'd still pick the simple version. Two of the rules up top come from this one: default to false, and plan to delete them.

File the delete ticket the same day

When you add a flag, file the ticket to delete it the same day. To make it stick, have a pre-commit hook reject any new line in config/features.php that doesn't have a ticket number on it, like // delete: BILL-142.

Nerd Out

About That Static

static $flags = null keeps the config around inside the function between calls, so the file loads once per request. Statics hide state and make tests harder, so if that one makes you twitch, fair enough. Some other ways to go:

  • Skip the cache. With opcache on, require is close to free; you're building a small array on each call. Measure before you bother.
  • Make it a class with one instance, registered in your container. Laravel's app()->singleton() and Symfony's service container hand out the same instance every time, and you can swap the binding in tests.
  • Inject a Feature service wherever you need it, like the class in From the Trenches. Yup, this is my pick. All it takes is a container that does a few good tricks, like inject and init, and nothing it doesn't need. Invert that dependency, my friends!

If you're just getting started, the static is fine. If your codebase already does dependency injection, register it as a singleton, or whatever pattern your container likes.


    Add your comment

    Comments show up after I approve them. No email address needed. Still no cookies.