Skip to content

fix(license): Cast return values in CustomerDataTrait for PHP 8.5 strict_types#8127

Open
theMosaad wants to merge 1 commit into
wp-media:developfrom
theMosaad:fix/php85-strict-types-customer-data-trait
Open

fix(license): Cast return values in CustomerDataTrait for PHP 8.5 strict_types#8127
theMosaad wants to merge 1 commit into
wp-media:developfrom
theMosaad:fix/php85-strict-types-customer-data-trait

Conversation

@theMosaad
Copy link
Copy Markdown

CustomerDataTrait::get_customer_key() and CustomerDataTrait::get_customer_email() declare string return types in a file with declare(strict_types=1). Both methods return values from Options_Data::get() and rocket_get_constant(), which return mixed. On PHP 8.5, when the stored value is not strictly a string, this throws a fatal TypeError.

This adds explicit (string) casts to all four return branches. The casts are backwards-compatible — casting a string to string is a no-op on older PHP versions.

Fixes #8126

`get_customer_key()` and `get_customer_email()` declare `string` return
types under `declare(strict_types=1)`, but `Options_Data::get()` and
`rocket_get_constant()` return `mixed`. On PHP 8.5 this throws a
`TypeError` when the stored value is not strictly a string.

Add explicit `(string)` casts to both return branches of both methods.
This is backwards-compatible — casting a string to string is a no-op.

Fixes wp-media#8126
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.

PHP 8.5: TypeError in CustomerDataTrait — strict_types return type mismatch

1 participant