docs: state the real key types accepted on PHP 8 - #38
Open
loks0n wants to merge 2 commits into
Open
Conversation
The constructor docblock still said 'string|resource', which predates PHP 8: openssl_pkey_get_private() now returns \OpenSSLAsymmetricKey, and validateKey() accepts the OpenSSL key/certificate objects while treating any string as a file:// path. The stale annotation makes static analyzers reject the correct object argument and steer callers toward passing PEM content as a string, which validateKey() can never accept (it fails with 'Invalid key: Should be resource of private key'). Exactly that caused utopia-php/vcs 5.2.4 to break GitHub App token generation in production (fixed in utopia-php/monorepo#160). Docblock/comment change only, no behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
Docblock/comment-only change — no behavior change (35 tests still pass).
JWT::__construct()$keyparam and the$keyproperty:string|resource→string|resource|\OpenSSLAsymmetricKey|\OpenSSLCertificate|\OpenSSLCertificateSigningRequest, with a note that for RS* a string is always treated as a file path, never as PEM content.validateKey()comment updated to say the same.Why
The
string|resourceannotation predates PHP 8, whereopenssl_pkey_get_private()returns\OpenSSLAsymmetricKeyinstead of a resource — whichvalidateKey()already accepts. Because the docblock omits the object types, static analyzers (PHPStan/Psalm) reject the correct call that passes the parsed key object, and nudge callers toward passing the PEM string instead — whichvalidateKey()can never accept (it prefixesfile://and fails withInvalid key: Should be resource of private key).That exact sequence happened in the wild: a refactor in utopia-php/vcs 5.2.4 satisfied the analyzer by passing the PEM string, which broke GitHub App token generation in production (fixed in utopia-php/monorepo#160). Correcting the annotation makes analyzers enforce the real contract instead of fighting it.
🤖 Generated with Claude Code