yii2-redis icon indicating copy to clipboard operation
yii2-redis copied to clipboard

Fix TypeError in yiisoft/yii2-redis Cache.php: "Unsupported operand types: string * int"

Open i-internet opened this issue 7 months ago • 1 comments

When running with PHP 8.3, the Redis cache component throws a TypeError with the message "Unsupported operand types: string * int" in the Cache.php file at line 251. Details

File: vendor/yiisoft/yii2-redis/src/Cache.php Line: 251 Code: $expire = (int) ($expire * 1000); Error: Unsupported operand types: string * int

This error occurs because PHP 8.3 is more strict about type operations than previous versions. The $expire variable might be passed as a string in some cases, causing the multiplication operation to fail. Proposed Solution Change line 251 from: php$expire = (int) ($expire * 1000); To: php$expire = (int) ((int)$expire * 1000); This ensures that $expire is properly cast to an integer before the multiplication operation. Environment

PHP version: 8.3 Yii2 Redis extension version: latest Yii2 framework version: latest

i-internet avatar Apr 19 '25 08:04 i-internet

What is the value of $expire in this case?

rob006 avatar Apr 19 '25 12:04 rob006