Feature Flag Determination

A feature flag has an on and off state. You will set different features according to each state.

Once a feature flag is applied, a specific user from your traffic should be able to either receive an off or on status. This on/off status determination can be done through the Hackle SDK.

IsFeatureOn

You can pass a feature key to the isFeatureOn() method to receive status results for the user. After receiving the status, we can then implement the logic according to each status.

In the example code below, we are passing feature key 42, and the user identifier of the user who will receive the status is "ae03e1adf".

<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae03e1adf");

$isFeatureOn = $client->isFeatureOn(42, $user);

if ($isFeatureOn) {
    // Feature for ON status
} else {
    // Feature for OFF status
}

?>

featureFlagDetail

The featureFlagDetail() method works the same as the isFeatureOn() method and additionally provides a reason for determining the status of a particular user. This can be useful when you want to check whether the manual allocation is working well or when you think that the traffic allocation you have set is not being reflected in your results.

You must pass a feature key as a parameter. For the example code below, we are passing feature key 42.

<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae03e1adf");

$featureFlagDecision = $client->featureFlagDetail(42, $user);

// whether feature is ON or OFF
$isOn = $featureFlagDecision->isOn();

// Status Determination reason
$reason = $featureFlagDecision->getReason();

?>

The reason for the status determination will be in the form of SDK_NOT_READY. Please refer to the table below for the full list of all the different types of reasons.

ReasonDescriptionFeature Status
SDK_NOT_READYThe SDK is not ready to use.
(e.g. Initialization with the wrong SDK key)
Default status(off)
FEATURE_FLAG_NOT_FOUNDNo feature flags were found for the feature key you passed.
The feature key may be incorrect or the corresponding feature flag may be in an archived state.
Default status(off)
FEATURE_FLAG_INACTIVEThe feature flag is inactive statusDefault status(off)
INDIVIDUAL_TARGET_MATCHMatched in individual user targeting. Status set for target
TARGET_RULE_MATCHMatched in audience targeting. Status set for target
DEFAULT_RULEDid not match in individual targeting or user targeting.Status set as default
EXCEPTIONAn unknown error has occurred.Default status(off)

Parameter

  • Parameter values of the distributed group can also be provided through the featureFlagDetail() method.
  • Parameter values you've set on the dashboard exists in the form of key and value, therefore you can use the method below to set the parameter values.
  • You can dynamically change the values in the parameter configuration screen of the feature flag.

getString

  • Returns the parameter value set to STRING, JSON type.
  • Returns the set value of the distributed group.
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae03e1adf");

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$strValue = $featureFlagDecision->getString("parameter_key_string_type", "defaultValue");
$jsonValue = $featureFlagDecision->getString("parameter_key_json_type", "defaultValue");
  
?>

getInt

  • Returns the parameter value set to Number type as Int type.
  • Returns the set value of the distributed group.
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae03e1adf");

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$intValue = $featureFlagDecision->getInt("parameter_key_number_type", 0);

?>

getFloat

  • Returns the parameter value set to Number type as Float type.
  • Returns the set value of the distributed group.
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae03e1adf");

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$floatValue = $featureFlagDecision->getFloat("parameter_key_number_type", 0.0);

?>

getBool

  • Returns the parameter value set to Bool type.
  • Returns the set value of the distributed group.
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae03e1adf");

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$boolValue = $featureFlagDecision->getBool("parameter_key_bool_type", true);

?>