Skip to content

Accept int timeout and null for $options parameter of Redis::set() in function map - #6801

Open
phpstan-bot wants to merge 1 commit into
phpstan:2.3.xfrom
phpstan-bot:create-pull-request/patch-u3791g8
Open

phpstan-bot wants to merge 1 commit into
phpstan:2.3.xfrom
phpstan-bot:create-pull-request/patch-u3791g8

Conversation

@phpstan-bot

Copy link
Copy Markdown
Collaborator

Summary

$redis->set('key', 'value', 3600) reported Parameter #3 $options of method Redis::set() expects array, int given. phpredis accepts an int TTL here (as well as an options array or null), so the call is valid.

Changes

  • resources/functionMap.php: Redis::set options= changed from array to array|int|null.

Root cause

The function map signature was narrower than phpredis's real signature (mixed $options = null, handled as array of options, integer timeout, or null). I compared all Redis/RedisCluster/RedisArray function map entries against the native reflection of the phpredis extension (null-default parameters not allowing null, and mixed options/timeout parameters). Redis::set was the only mismatch. RedisCluster::set is not in the function map, so it already uses the native mixed signature.

Test

Added tests/PHPStan/Rules/Methods/data/bug-15393.php with CallMethodsRuleTest::testBug15393. It covers set() with no options, an int timeout, an options array, and null. Before the fix, the int and null calls failed.

Fixes phpstan/phpstan#15393

…et()` in function map

- phpredis declares `Redis::set(string $key, mixed $value, mixed $options = null)`;
  `$options` may be an array of options, an int TTL in seconds (legacy form), or null.
  The function map narrowed it to `array`, causing false positives.
- Compared every Redis/RedisCluster/RedisArray entry in functionMap.php against the
  native signatures of the loaded phpredis extension (null-default parameters and
  `mixed` options/timeout parameters); `Redis::set` was the only mismatch.
@VincentLanglet
VincentLanglet requested a review from staabm October 24, 2026 15:31
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.

Redis::set got error Parameter #3 $options of method Redis::set() expects array, int given

2 participants