feat: add caller-supplied default value to FeatureFlagEvaluations::isEnabled() - #216
Draft
posthog[bot] wants to merge 1 commit into
Draft
feat: add caller-supplied default value to FeatureFlagEvaluations::isEnabled()#216posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
…bled() Adds an optional `$defaultValue` parameter so callers can distinguish "flag resolved to false" from "flag has no value" (missing key, not loaded, failed request). Generated-By: PostHog Code Task-Id: 11d33c8f-53c1-4d18-bd8f-2da5e8678f4e
Contributor
posthog-php Compliance ReportDate: 2026-08-08 16:08:33 UTC ✅ All Tests Passed!46/46 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Brings
posthog-phpinto compliance with theis-feature-enabledspec in PostHog/sdk-specs, which is a hardSHALLwith no server-SDK carve-out: "The SDK SHALL accept a caller-supplied boolean default ... and SHALL return it whenever the flag has no value ... A flag that has a value — includingfalse— always wins over the caller-supplied default."Per the compliance audit (
compliance/posthog-php.md#n8), the legacyClient::isFeatureEnabled()lacks this, but that method is already deprecated in favor ofClient::evaluateFlags()+FeatureFlagEvaluations::isEnabled(). The canonical, non-deprecatedFeatureFlagEvaluations::isEnabled(string $key): boolhas the same gap: it hardcodes?? falseon a miss, so a genuinely-disabled flag and an unresolved/unknown flag are indistinguishable, and there's no way for a caller to opt into atruefallback.This PR fixes the canonical path (not the deprecated legacy method, per guidance not to invest further in deprecated APIs) by adding an optional
defaultValueparameter.What changed
FeatureFlagEvaluations::isEnabled(string $key, bool $defaultValue = false): bool— the default is returned only when the flag has no resolvable value; any real value (includingfalse) still wins..changeset/feature-flag-evaluations-default-value.mdper this repo's release process.api/public-api.jsonviacomposer api:updateto reflect the new optional parameter.Backwards compatibility
Purely additive — the new parameter is optional and defaults to
false, which is exactly today's unconditional fallback behavior. No existing caller's behavior changes.💚 How did you test it?
test/FeatureFlagEvaluationsTest.php:testIsEnabledReturnsCallerSuppliedDefaultForUnknownKey— unknown key returns the caller-supplied default (true/false), and still defaults tofalsewhen omitted.testIsEnabledDefaultDoesNotOverrideARealFalseValue— a flag that resolves to a realfalseis not overridden bydefaultValue: true.vendor/bin/phpunit— 447 tests, 3808 assertions, all passing.composer api:check(viascripts/check-public-api.php) to confirm the only public API delta is the new optional parameter, thencomposer api:updateto refresh the snapshot.phpcs --standard=phpcs.xmlagainst the changed files — clean.📝 Checklist
If releasing new changes
.changeset/*.mdchange intent file🤖 Agent context
Autonomy: Fully autonomous
This PR was produced by an unattended, scheduled agent run ("Daily SDK Compliance Implementer") that reads the compliance matrices in PostHog/sdk-specs and implements one backward-compatible remediation per run. The candidate was selected from the matrix's global open-gaps list, cross-checked against this repo's open PRs/branches for duplicates (none found — an old, already-merged 2022 branch,
ff-remove-defaultvalue, was a false-positive name match, unrelated to this change), and implemented directly against the canonical (non-deprecated)isEnabled()API rather than the deprecated legacy method.Created with PostHog Code