Skip to content

docs: fix inaccuracies in README code examples#172

Open
jonathannorris wants to merge 1 commit intomainfrom
fix/readme-accuracy
Open

docs: fix inaccuracies in README code examples#172
jonathannorris wants to merge 1 commit intomainfrom
fix/readme-accuracy

Conversation

@jonathannorris
Copy link
Copy Markdown
Member

Summary

  • Fix code examples in the README that would throw errors at runtime if copy-pasted
  • Replace references to non-existent UnimplementedHook and Go SDK terminology

Changes

  1. Targeting section: Fixed new EvaluationContext('targetingKey', [...]) to new EvaluationContext('targetingKey', new Attributes([...])). The constructor's second argument is typed ?AttributesInterface, so passing a plain array throws a TypeError. Applied to all three EvaluationContext instantiations
  2. Hooks section: Fixed $api->addHook(...) and $client->addHook(...) (singular) to addHooks(...) (plural). Only the plural method exists; the singular would throw Call to undefined method
  3. Extended Example: Added missing use OpenFeature\OpenFeatureAPI; import — the example calls OpenFeatureAPI::getInstance() but only imports OpenFeatureClient
  4. Provider extension example: Added missing use OpenFeature\implementation\provider\AbstractProvider; import. Also aliased the ResolutionDetails import to ResolutionDetailsInterface to match the return type hints used throughout the example
  5. Hook development section: Removed reference to non-existent UnimplementedHook "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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md
Comment thread README.md
Comment thread README.md
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EvaluationContext construction in the Targeting examples by passing an Attributes instance instead of an array.
  • Correct hook registration calls from addHook to addHooks (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 align ResolutionDetails naming with the example’s return type hints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
@jonathannorris jonathannorris requested review from a team April 17, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants