Generated banner for Feature Flags Php
Generated logo for Feature Flags Php

Feature Flags Php

PostHogOfficialCreated by PostHog

  • Skill
  • Tool integration
  • Data and AI
  • MIT
  • No issues found

From the author

PostHog feature flags for PHP applications
— the description by PostHog

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides guidance and best practices for implementing PostHog feature flags within PHP applications. It covers the integration of the PostHog PHP SDK, emphasizing server-side evaluation to prevent UI flickering and ensuring consistent flag behavior. The skill includes instructions on managing flags, using environment variables for configuration, and adhering to clean coding standards by minimizing flag dispersion throughout the codebase.

What it does

  • Provides patterns for integrating PostHog feature flags in PHP environments.
  • Outlines best practices for flag naming, targeting, and lifecycle management.
  • Explains how to use the PostHog PHP SDK for server-side flag evaluation.
  • Offers guidance on using environment variables for secure API key management.
  • Suggests architectural patterns to keep feature flag logic clean and maintainable.

When to use it

  • When you need to implement feature toggles in a PHP-based backend.
  • When you want to perform server-side feature flag evaluation to improve performance.
  • When you need to standardize how feature flags are accessed across your PHP application.
  • When you are setting up new experiments or phased feature releases in a PHP project.

Advantages

  • Reduces UI flicker by enabling server-side flag evaluation.
  • Promotes clean code through centralized flag handling.
  • Ensures secure configuration via environment variables.
  • Provides clear conventions for naming and organizing feature flags.

Usage examples

“How do I initialize the PostHog PHP SDK for feature flags?”
The agent will explain the use of PostHog::init() and emphasize that it should be called once, using environment variables for the API key.
“What is the best way to check a feature flag in my PHP controller?”
The agent will recommend wrapping the flag check in a dedicated function or method to keep the controller logic clean and maintainable.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/posthog/feature-flags-php/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip feature-flags-php.zip -d .agents/skills

Documentation by PostHog

PostHog feature flags for PHP

This skill helps you add PostHog feature flags to PHP applications.

Reference files

  • references/php.md - Php feature flags installation - docs

  • references/adding-feature-flag-code.md - Adding feature flag code - docs

  • references/best-practices.md - Feature flag best practices - docs

Consult the documentation for API details and framework-specific patterns.

Key principles

  • Environment variables: Always use environment variables for PostHog keys. Never hardcode them.

  • Minimal changes: Add feature flag code alongside existing logic. Don't replace or restructure existing code.

  • Boolean flags first: Default to boolean flag checks unless the user specifically asks for multivariate flags.

  • Server-side when possible: Prefer server-side flag evaluation to avoid UI flicker.

PostHog MCP tools

Check if a PostHog MCP server is connected. If available, look for tools related to feature flag management (creating, listing, updating, deleting flags). Use these tools to manage flags directly in PostHog rather than requiring the user to do it manually in the dashboard.

Framework guidelines

  • Remember that source code is available in the vendor directory after composer install

  • posthog/posthog-php is the PHP SDK package name

  • Check composer.json for existing dependencies and autoload configuration before adding new files

  • The PHP SDK uses static methods (PostHog::capture, PostHog::identify) - initialize once with PostHog::init()

  • PHP SDK methods take associative arrays with 'distinctId', 'event', 'properties' keys - not positional arguments

Files

references/php.md

PHP feature flags installation - Docs

  1. 1

    Install the package

    Required

    Install the PostHog PHP library using Composer:

    Terminal

    PostHog AI

    composer require posthog/posthog-php
  2. 2

    Configure PostHog

    Required

    Initialize the PostHog client with your project token and host:

    PHP

    PostHog AI

    PostHog\PostHog::init(
        '<ph_project_token>',
        ['host' => 'https://us.i.posthog.com']
    );
  3. 3

    Send events

    Recommended

    Once installed, you can manually send events to test your integration:

    PHP

    PostHog AI

    PostHog::capture([
        'distinctId' => 'test-user',
        'event' => 'test-event',
    ]);
  4. 4

    Evaluate boolean feature flags

    Required

    Check if a feature flag is enabled:

    $isMyFlagEnabledForUser = PostHog::isFeatureEnabled('flag-key', 'distinct_id_of_your_user')
    if ($isMyFlagEnabledForUser) {
        // Do something differently for this user
    }
  5. 5

    Evaluate multivariate feature flags

    Optional

    For multivariate flags, check which variant the user has been assigned:

    $enabledVariant = PostHog::getFeatureFlag('flag-key', 'distinct_id_of_your_user')
    if ($enabledVariant === 'variant-key') { # replace 'variant-key' with the key of your variant
        # Do something differently for this user
    }
  6. 6

    Include feature flag information in events

    Required

    If you want to use your feature flag to breakdown or filter events in your insights, you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.

    Note: This step is only required for events captured using our server-side SDKs or API.

    Set send_feature_flags to true in your capture call:

    PHP

    PostHog AI

    PostHog::capture(array(
        'distinctId' => 'distinct_id_of_your_user',
        'event' => 'event_name',
        'send_feature_flags' => true
    ));

    Include $feature property

    Include the $feature/feature_flag_name property in your event properties:

    PHP

    PostHog AI

    PostHog::capture(array(
        'distinctId' => 'distinct_id_of_your_user',
        'event' => 'event_name',
        'properties' => array(
            '$feature/feature-flag-key' => 'variant-key' // replace feature-flag-key with your flag key. Replace 'variant-key' with the key of your variant
        )
    ));
  7. 7

    Override server properties

    Optional

    Sometimes, you may want to evaluate feature flags using properties that haven't been ingested yet, or were set incorrectly earlier. You can provide properties to evaluate the flag with:

    PostHog::getFeatureFlag(
        'flag-key',
        'distinct_id_of_the_user',
        [
            'your_group_type' => 'your_group_id',
            'another_group_type' => 'your_group_id'
        ], // groups
        ['property_name' => 'value'], // person properties
        [
            'your_group_type' => ['group_property_name' => 'value'],
            'another_group_type' => ['group_property_name' => 'value']
        ], // group properties
        false, // onlyEvaluateLocally, Optional. Defaults to false.
        true // sendFeatureFlagEvents
    )
  8. 8

    Running experiments

    Optional

    Experiments run on top of our feature flags. Once you've implemented the flag in your code, you run an experiment by creating a new experiment in the PostHog dashboard.

  9. 9

    Next steps

    Recommended

    Now that you're evaluating flags, continue with the resources below to learn what else Feature Flags enables within the PostHog platform.

    ResourceDescription
    Creating a feature flagHow to create a feature flag in PostHog
    Adding feature flag codeHow to check flags in your code for all platforms
    Framework-specific guidesSetup guides for React Native, Next.js, Flutter, and other frameworks
    How to do a phased rolloutGradually roll out features to minimize risk
    More tutorialsOther real-world examples and use cases
Community questions

Ask a question

Was this page useful?

HelpfulCould be better

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs an MCP server

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
PostHog
Publisher
PostHog (Official)
Source
PostHog/skills · skills/posthog/feature-flags/skills/php · commit a5d30e7
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
PostHog/skills

AutoGineer is not affiliated with or endorsed by PostHog.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download feature-flags-php.zip