> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.getunleash.io/sdks/openfeature/php/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.getunleash.io/_mcp/server. # PHP OpenFeature provider > Set up the Unleash OpenFeature provider for PHP to evaluate feature flags through the OpenFeature API. The [Unleash OpenFeature PHP provider](https://github.com/Unleash/unleash-openfeature-php-provider) lets PHP applications evaluate Unleash feature flags through the [OpenFeature](https://openfeature.dev/) API. The provider wraps the [Unleash PHP SDK](/sdks/php) and uses the same backend SDK behavior for fetching and caching feature flag data, local evaluation, and metrics. ## Requirements * PHP 8.4 or later ## Installation Install the provider with Composer. The provider declares the OpenFeature PHP SDK and the [Unleash PHP SDK](/sdks/php) as dependencies, together with default HTTP client and cache implementations, so you don't need to add them separately. ```bash composer require unleash/openfeature-provider ``` ## Configuration Create an `UnleashBuilder` with the same [options](/sdks/php#builder) you would use to configure the Unleash PHP SDK client, then pass it to an `UnleashFlagProvider` and register the provider with OpenFeature. The provider builds the Unleash client from the builder. ```php withAppName('my-php-app') ->withAppUrl('/api') ->withInstanceId('my-php-app-1') ->withHeader('Authorization', ''); OpenFeatureAPI::getInstance()->setProvider(new UnleashFlagProvider($builder)); ``` To log provider diagnostics, such as discarded context fields, pass a [PSR-3](https://www.php-fig.org/psr/psr-3/) logger as the second constructor argument: `new UnleashFlagProvider($builder, $logger)`. ## Evaluate a flag Build an OpenFeature client and evaluate flags through the OpenFeature API: ```php getClient(); $context = new EvaluationContext('user-123'); $enabled = $client->getBooleanValue('my-feature', false, $context); ``` The provider supports all OpenFeature evaluation methods. Boolean evaluation uses the flag's enabled state. All other types resolve from the payload of the flag's [variant](/concepts/feature-flag-variants): * String values accept `string` and `csv` payloads. * Integer and float values accept `number` payloads. * Object values accept `json` payloads. If the flag doesn't exist, the flag is disabled, or the variant payload is missing, has a different type, or can't be parsed, the evaluation returns the default value. The detail methods, such as `getBooleanDetails`, additionally report the evaluation reason and the assigned variant name. ## Context mapping The provider maps the OpenFeature evaluation context to an [Unleash context](/concepts/unleash-context) before each evaluation. The following OpenFeature fields map directly to top-level Unleash context fields: * `currentTime` * `userId` * `sessionId` * `remoteAddress` * `environment` If you set a targeting key, the provider maps it to `userId`. The targeting key takes precedence over a `userId` field set on the evaluation context. The `appName` comes from the builder configuration, not the evaluation context. The provider adds all other scalar fields, such as strings, numbers, booleans, and date-time values, to the Unleash context [properties](/concepts/unleash-context#the-properties-field). It discards nested values, such as arrays. ## Example To try the provider against your Unleash instance, clone the [provider repository](https://github.com/Unleash/unleash-openfeature-php-provider) and run the [boolean flag example](https://github.com/Unleash/unleash-openfeature-php-provider/blob/main/examples/boolean_flag.php) with your Unleash URL and API token: ```bash composer install php examples/boolean_flag.php \ --url '/api' \ --api-key "$UNLEASH_API_KEY" \ --flag-key my-feature \ --targeting-key user-123 ``` > Set up the Unleash OpenFeature provider for PHP to evaluate feature flags through the OpenFeature API.