Skip to content

docs: state the real key types accepted on PHP 8 - #38

Open
loks0n wants to merge 2 commits into
adhocore:mainfrom
loks0n:fix/php8-key-docblock
Open

docs: state the real key types accepted on PHP 8#38
loks0n wants to merge 2 commits into
adhocore:mainfrom
loks0n:fix/php8-key-docblock

Conversation

@loks0n

@loks0n loks0n commented Aug 25, 2026

Copy link
Copy Markdown

What

Docblock/comment-only change — no behavior change (35 tests still pass).

  • JWT::__construct() $key param and the $key property: string|resourcestring|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|resource annotation predates PHP 8, where openssl_pkey_get_private() returns \OpenSSLAsymmetricKey instead of a resource — which validateKey() 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 — which validateKey() can never accept (it prefixes file:// and fails with Invalid 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

loks0n and others added 2 commits August 25, 2026 10:31
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>
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.

1 participant