I assume that you already are aware of the subject so I am not going to explain what "feature flag" is. Instead, I'll explain how I would use it.


A feature flag should be safe to remove so that the code gracefully falls back to the "accepted/default" behaviour in the case of its absence without touching the code. The only question you should always ask yourself is, "By default, is this feature enabled or disabled?".


Example


You have a website that has a "super admin login" feature. A super admin can do anything in the site after login. Assume that this is the "default" behaviour so that's why it was implemented in the first place. If we are to control this feature with a feature flag, we would do as shown below.


Q: "By default, is this feature enabled or disabled?"
A: "Yes, enabled!"


// This is the feature flag.
SUPER_ADMIN_LOGIN_ENABLED: true

// This is the code that depends on the feature flag in login file.
if (ENABLE_SUPER_ADMIN_LOGIN == false) {
echo "super admin login has been disabled"
exit;
} else { // null (absence) or true
echo "super admin login has been enabled"
continue;
}

As you can see above, if you ever remove the feature flag, you system will gracefully fallback to "accepted/default" behaviour which is super admin login has been enabled.