Skip to content

Add false to Redis::mget() return type#5831

Open
benconda wants to merge 1 commit into
phpstan:2.2.xfrom
benconda:redis-mget-false-return
Open

Add false to Redis::mget() return type#5831
benconda wants to merge 1 commit into
phpstan:2.2.xfrom
benconda:redis-mget-false-return

Conversation

@benconda

@benconda benconda commented Jun 9, 2026

Copy link
Copy Markdown

Summary

The functionMap entry for Redis::mget() is missing false from its return type:

'Redis::mget' => ['__benevolent<Redis|array<string, mixed>>', 'keys'=>'string[]'],

phpredis returns false on error. The false was added to mget()'s declared return type in phpredis 6.1.0:

phpredis Redis::mget() declared return
≤ 6.0.x Redis|array
≥ 6.1.0 Redis|array|false

This is confirmed by native reflection on a current extension (e.g. ext-redis 6.3.0):

ReflectionMethod(Redis::class, 'mget')->getReturnType()  // Redis|array|false

It is also inconsistent with the sibling entry right next to it, Redis::hMget, which already includes false:

'Redis::hMget' => ['__benevolent<Redis|array<string, mixed>|false>', 'key'=>'string', 'fields'=>'string[]'],

Effect

Before this change, PHPStan reports a === false check on an mget() result as identical.alwaysFalse ("will always evaluate to false"), and a method whose return type correctly includes false triggers return.unusedType. In practice this hides a real runtime failure mode (mget() returning false on a transport/error condition) on phpredis 6.1.0+.

Changes

  • resources/functionMap.php: add false to Redis::mget(), mirroring Redis::hMget. This matches phpredis 6.1.0+ (the current line); on the older 6.0.x the extension declared Redis|array, but the functionMap targets the current extension version.
  • tests/PHPStan/Analyser/nsrt/redis-mget.php: regression test asserting the return type is (array<string, mixed>|Redis|false) and narrows correctly after a === false guard. Verified the test fails without the functionMap change.

phpredis returns false on error, so the correct return type is
Redis|array|false (confirmed by native reflection in ext-redis >= 6).
The functionMap entry omitted it, while the sibling Redis::hMget right
next to it already includes false. This aligns mget with hMget and the
actual extension signature.

Adds a regression test asserting the return type and its narrowing
after a === false guard.
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.

1 participant