The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Update usage from older versions of the PHP SDK

Descibes how to update from older versions of the Optimizely Full Stack (Legacy) PHP SDK to Optimizely Feature Experimentation.

This section provides code examples for how Optimizely recommends leveraging the new Decision and Event Tracking APIs. All existing Full Stack (Legacy) methods and implementation are still supported. See Optimizely Feature Experimentation - application & migration documentation for the latest updates.

Optimizely recommends adopting the new Decide, Decide All, and Track Event methods as a more flexible and easier-to-use replacement where you currently use isFeatureEnabled, getFeatureVariable, getAllFeatures, or Track calls within your implementation.

The following are examples of how to migrate the Full Stack (Legacy) methods to Feature Experimentation methods:

// -------------------------------
// Prereq for new methods: create a user
// ------------------------------
$attributes = ['is_logged_in' => true];
$user = $optimizely->createUserContext('user_123', $attributes);

// -------------------------------
// Is Feature Enabled 
// ------------------------------
// old method
$enabled = $optimizely->isFeatureEnabled('flag_1', 'user_123', $attributes);

// new method
$decision = $user->decide('flag_1');
$enabled = $decision->getEnabled();

// -------------------------------
// Activate & Get Variation 
// ------------------------------
// old method
$variationKey = $optimizely->activate('experiment_1', 'user_123', $attributes);
// new method
$variationKey = $decision->getVariationKey();



// -------------------------------
// Get All Feature Variables 
// ------------------------------
// old method
$allVarValues = $optimizely->getAllFeatureVariables('flag_1',
                                                   'user_123',
                                                   $attributes); 
// new method
$allVarValues = $decision->getVariables();


// -------------------------------
// Get Enabled Features 
// ------------------------------
// old method
$enabledFlags = $optimizely->getEnabledFeatures('user_123');

// new method
$decisions = $user->decideAll(['ENABLED_FLAGS_ONLY']);
$enabledFlags = array_keys($decisions);


// -------------------------------
// Track 
// ------------------------------
// old method
$optimizely->track('my_purchase_event_key',
                   'user_123',
                   $attributes,
                   ['purchase_count' => 2]);

// new method
$user->trackEvent('my_purchase_event_key', ['purchase_count' => 2]);