Skip to content

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

@i-internet

Description

@i-internet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions