Skip to content

Widen Redis::set() $options, Redis::sInter()/RedisCluster::sInter() $key and Redis::zCount() bounds in functionMap to match phpredis signatures - #6940

Merged
VincentLanglet merged 1 commit into
phpstan:2.3.xfrom
phpstan-bot:create-pull-request/patch-fdncsh4
Nov 4, 2026
Merged

VincentLanglet merged 1 commit into
phpstan:2.3.xfrom
phpstan-bot:create-pull-request/patch-fdncsh4

Conversation

@phpstan-bot

Copy link
Copy Markdown
Collaborator

Summary

Redis::set() accepts an integer TTL as its third argument ($redis->set('key', 'value', 60) makes phpredis send SETEX), as well as null. PHPStan's functionMap only allowed array, so it reported Parameter #3 $options of method Redis::set() expects array, int given. This PR widens the parameter type to match phpredis.

Changes

  • resources/functionMap.php:
    • Redis::set options: array → array|int|null
    • Analogous cases found by comparing every Redis*:: functionMap entry with the native signatures that the phpredis extension reports through reflection:
      • Redis::sInter and RedisCluster::sInter key: string → string|string[] (native type is array|string)
      • Redis::zCount start/end: string → string|int (native type is string|int)
    • The other differences I found look like intentional refinements, so I left them alone: array shapes for options, string[] instead of array, ?int for by-ref scan iterators, and narrower types where the native type is mixed.

Root cause

The hand-written functionMap signatures were narrower than the actual phpredis signatures, so PHPStan rejected valid arguments.

Test

CallMethodsRuleTest::testBug15393 (tests/PHPStan/Rules/Methods/data/bug-15393.php) covers Redis::set() with an int, array, null, omitted, and invalid string $options. It also covers Redis::sInter()/RedisCluster::sInter() with an array of keys and Redis::zCount() with int bounds. Every case except the invalid string reported a false positive before the fix.

Fixes phpstan/phpstan#15393

…ter()` `$key` and `Redis::zCount()` bounds in functionMap to match phpredis signatures

- `Redis::set()` `$options`: `array` -> `array|int|null` (phpredis accepts an int TTL, sending SETEX, or null)
- `Redis::sInter()` and `RedisCluster::sInter()` `$key`: `string` -> `string|string[]` (native `array|string`)
- `Redis::zCount()` `$start`/`$end`: `string` -> `string|int` (native `string|int`)
- Audited all Redis/RedisCluster/RedisArray/RedisSentinel functionMap entries against
  the native signatures of the phpredis extension; remaining differences are intentional
  refinements (array shapes, string[] instead of array, by-ref scan iterators).
@VincentLanglet
VincentLanglet requested a review from staabm November 4, 2026 09:35
@VincentLanglet VincentLanglet self-assigned this Nov 4, 2026
@staabm

staabm commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

shouldn't issue-bot report the initial snippet as beeing fixed by the PR?

@VincentLanglet

Copy link
Copy Markdown
Contributor

shouldn't issue-bot report the initial snippet as beeing fixed by the PR?

It does https://github.com/phpstan/phpstan-src/actions/runs/41806668097?pr=6940

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - I think the issue bot result was not there at the time I looked because github currently has some problems

@VincentLanglet
VincentLanglet merged commit 0b063d3 into phpstan:2.3.x Nov 4, 2026
1039 of 1042 checks passed
@staabm
staabm deleted the create-pull-request/patch-fdncsh4 branch November 4, 2026 11:01
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

3 participants