Bug Description
CustomerDataTrait::get_customer_key() and CustomerDataTrait::get_customer_email() in inc/Engine/License/API/CustomerDataTrait.php declare string return types. The file uses declare(strict_types=1).
However, 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 (e.g., an integer from the database), this causes a fatal TypeError:
TypeError: CustomerDataTrait::get_customer_key(): Return value must be of type string, int returned
Steps to Reproduce
- Install WP Rocket 3.20.5 on PHP 8.5
- Activate WP Rocket with a valid license
- Visit any page — the
TypeError is triggered during license validation
Expected Behavior
Methods should return a string without throwing a TypeError.
Proposed Fix
Add explicit (string) casts to the return values in both methods. This is backwards-compatible — casting a string to string is a no-op on older PHP versions.
protected function get_customer_key(): string {
return ! empty( $this->options->get( 'consumer_key', '' ) )
- ? $this->options->get( 'consumer_key', '' )
- : rocket_get_constant( 'WP_ROCKET_KEY', '' );
+ ? (string) $this->options->get( 'consumer_key', '' )
+ : (string) rocket_get_constant( 'WP_ROCKET_KEY', '' );
}
protected function get_customer_email(): string {
return ! empty( $this->options->get( 'consumer_email', '' ) )
- ? $this->options->get( 'consumer_email', '' )
- : rocket_get_constant( 'WP_ROCKET_EMAIL', '' );
+ ? (string) $this->options->get( 'consumer_email', '' )
+ : (string) rocket_get_constant( 'WP_ROCKET_EMAIL', '' );
}
I'll submit a PR with this fix shortly.
Environment
- WP Rocket version: 3.20.5
- PHP version: 8.5
- WordPress version: 6.9.1
Bug Description
CustomerDataTrait::get_customer_key()andCustomerDataTrait::get_customer_email()ininc/Engine/License/API/CustomerDataTrait.phpdeclarestringreturn types. The file usesdeclare(strict_types=1).However, both methods return values from
Options_Data::get()androcket_get_constant(), which returnmixed. On PHP 8.5, when the stored value is not strictly a string (e.g., an integer from the database), this causes a fatalTypeError:Steps to Reproduce
TypeErroris triggered during license validationExpected Behavior
Methods should return a string without throwing a
TypeError.Proposed Fix
Add explicit
(string)casts to the return values in both methods. This is backwards-compatible — casting a string to string is a no-op on older PHP versions.protected function get_customer_key(): string { return ! empty( $this->options->get( 'consumer_key', '' ) ) - ? $this->options->get( 'consumer_key', '' ) - : rocket_get_constant( 'WP_ROCKET_KEY', '' ); + ? (string) $this->options->get( 'consumer_key', '' ) + : (string) rocket_get_constant( 'WP_ROCKET_KEY', '' ); } protected function get_customer_email(): string { return ! empty( $this->options->get( 'consumer_email', '' ) ) - ? $this->options->get( 'consumer_email', '' ) - : rocket_get_constant( 'WP_ROCKET_EMAIL', '' ); + ? (string) $this->options->get( 'consumer_email', '' ) + : (string) rocket_get_constant( 'WP_ROCKET_EMAIL', '' ); }I'll submit a PR with this fix shortly.
Environment