docs: fix inaccuracies in README code examples#172
docs: fix inaccuracies in README code examples#172jonathannorris wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the README.md to align with recent API changes, including the requirement of the Attributes class in EvaluationContext, the renaming of addHook to addHooks, and updated guidance for hook implementations. The review feedback correctly identifies that several code examples are missing necessary 'use' statements for classes like OpenFeatureAPI, EvaluationContext, Attributes, and EvaluationOptions, which would prevent the examples from being runnable if copy-pasted. Additionally, a missing import or backslash for the Throwable type hint in the hook examples was noted as a potential runtime issue.
There was a problem hiding this comment.
Pull request overview
Updates README PHP code examples to match the current SDK API and avoid runtime errors when readers follow the documentation.
Changes:
- Fix
EvaluationContextconstruction in the Targeting examples by passing anAttributesinstance instead of an array. - Correct hook registration calls from
addHooktoaddHooks(variadic API) and fix hook-development guidance to match PHP SDK types/method names. - Add missing imports in README examples (e.g.,
OpenFeatureAPI,AbstractProvider) and alignResolutionDetailsnaming with the example’s return type hints.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
53b4197 to
80577de
Compare
Summary
UnimplementedHookand Go SDK terminologyChanges
new EvaluationContext('targetingKey', [...])tonew EvaluationContext('targetingKey', new Attributes([...])). The constructor's second argument is typed?AttributesInterface, so passing a plain array throws aTypeError. Applied to all threeEvaluationContextinstantiations$api->addHook(...)and$client->addHook(...)(singular) toaddHooks(...)(plural). Only the plural method exists; the singular would throwCall to undefined methoduse OpenFeature\OpenFeatureAPI;import — the example callsOpenFeatureAPI::getInstance()but only importsOpenFeatureClientuse OpenFeature\implementation\provider\AbstractProvider;import. Also aliased theResolutionDetailsimport toResolutionDetailsInterfaceto match the return type hints used throughout the exampleUnimplementedHook"struct" (copied from Go SDK docs). Replaced with accurate description pointing to the typed abstract base classes (BooleanHook,StringHook, etc.) that PHP SDK actually provides. Fixed method name casing (Before/After/...) to match actual PHP method names (before/after/...)All fixed examples were verified to execute successfully against the current main branch.