Add false to Redis::mget() return type#5831
Open
benconda wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
functionMapentry forRedis::mget()is missingfalsefrom its return type:phpredis returns
falseon error. Thefalsewas added tomget()'s declared return type in phpredis 6.1.0:Redis::mget()declared returnRedis|arrayRedis|array|falseThis is confirmed by native reflection on a current extension (e.g. ext-redis 6.3.0):
It is also inconsistent with the sibling entry right next to it,
Redis::hMget, which already includesfalse:Effect
Before this change, PHPStan reports a
=== falsecheck on anmget()result asidentical.alwaysFalse("will always evaluate to false"), and a method whose return type correctly includesfalsetriggersreturn.unusedType. In practice this hides a real runtime failure mode (mget()returningfalseon a transport/error condition) on phpredis 6.1.0+.Changes
resources/functionMap.php: addfalsetoRedis::mget(), mirroringRedis::hMget. This matches phpredis 6.1.0+ (the current line); on the older 6.0.x the extension declaredRedis|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=== falseguard. Verified the test fails without the functionMap change.