Skip to content

Fix the type of the options of the RedisArray constructor - #6399

Merged
staabm merged 2 commits into
phpstan:2.2.xfrom
mlocati-forks:redis-array-options-type
Sep 17, 2026
Merged

staabm merged 2 commits into
phpstan:2.2.xfrom
mlocati-forks:redis-array-options-type

Conversation

@mlocati

@mlocati mlocati commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The options may have any type: for example, connect_timeout and read_timeout are numbers, lazy_connect and consistent are booleans, function and distributor are callables, previous is an array.

See the phpredis documentation of RedisArray:
https://github.com/phpredis/phpredis/blob/develop/arrays.md
and the phpredis stub of the constructor:
https://github.com/phpredis/phpredis/blob/develop/redis_array.stub.php

@phpstan-bot

Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 2.3.x. PHPStan 2.3 is not going to be released for months. If your code is relevant on 2.2.x and you want it to be released sooner, please rebase your pull request and change its target to 2.2.x.

@mlocati
mlocati changed the base branch from 2.3.x to 2.2.x September 8, 2026 14:58
@mlocati
mlocati force-pushed the redis-array-options-type branch from 93fa9f6 to 0af0a71 Compare September 8, 2026 14:59
@mlocati

mlocati commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

please rebase your pull request and change its target to 2.2.x

Done.

The options may have any type: for example, connect_timeout and
read_timeout are numbers, lazy_connect and consistent are booleans,
function and distributor are callables, previous is an array.

See the phpredis documentation of RedisArray:
https://github.com/phpredis/phpredis/blob/develop/arrays.md
and the phpredis stub of the constructor:
https://github.com/phpredis/phpredis/blob/develop/redis_array.stub.php
@mlocati
mlocati force-pushed the redis-array-options-type branch from 0af0a71 to 8b6f1aa Compare September 17, 2026 06:54
@staabm

staabm commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

@SanderMuller please review

@SanderMuller

Copy link
Copy Markdown
Contributor

I am not a maintainer, so the merge call is @staabm's. I verified the change rather than read it, and it does what it says.

The type claim holds. The arrays.md you linked documents six different value types. previous is an array. function and distributor are callables. lazy_connect, consistent and autorehash are booleans. connect_timeout and read_timeout are doubles, retry_interval is an int, and algorithm and auth are strings. array<string, string> cannot describe that.

Base against your head, on a file that passes one option of every documented type:

base   Parameter #2 $options of class RedisArray constructor expects array<string, string>,
       array<string, bool|(Closure)|float|int|list<string>|string> given.
head   no error

One thing I would add while you are in there. The parameter is still not nullable, so the documented default is a false positive:

new RedisArray($hosts, null);
head   Parameter #2 $options of class RedisArray constructor expects array<string, mixed>, null given.

redis_array.stub.php declares __construct(string|array $name_or_hosts, ?array $options = null). Changing the entry to '?array<string, mixed>' takes that file to zero errors, and the same shape is already used two hundred lines above for Redis::copy:

'Redis::copy' => [..., 'options='=>'?array<string, mixed>'],

Your call whether that belongs here or in a separate PR.

Checked and found fine: stubs/Redis.stub declares class RedisArray {} with no constructor, so nothing there contradicts the map, and there is no other RedisArray::__construct entry.

Gate on your head: full suite green, 21440 tests. The signature map suite is green too, 2844 tests and 64036 assertions. No performance statement is needed beyond the obvious: this is a data entry read through the signature map, with no runtime path.

CI: 31 of the 32 red checks also fail on other open 2.2.x pull requests, so they are the base. The one that does not, Result cache E2E tests (result-cache-relative-path), failed on could not download checksum from .../bashunit/releases/download/0.44.0/checksum, which is infrastructure rather than your change.

@mlocati

mlocati commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

One thing I would add while you are in there. The parameter is still not nullable, so the documented default is a false positive:

new RedisArray($hosts, null);

Fixed, thanks!.

@SanderMuller SanderMuller 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.

Verified on 672a020ec. The repro that failed twice on the base now reports nothing. The three cases that should still be rejected still are: a non-array second argument, an array<int, string>, and an int for the first parameter.

Gate on your head is green. Full suite 21440 tests, signature map 2844 tests and 64036 assertions. No performance note beyond the obvious, since this is a data entry read through the signature map with no runtime path. There is no test in the diff because a functionMap entry has nowhere to put one, so I checked the behaviour with a file instead.

Your six red checks that other open 2.2.x pull requests do not share are the base, not you. Lint fails on Parse error: tests/PHPStan/Rules/DeadCode/data/dynamic-name-always-terminating.php:20, and Name Collision Detector on Bug15244\Foo is defined 2 times. Both files are on 2.2.x already and neither is in your one-line diff.

@staabm
staabm merged commit 4c537c2 into phpstan:2.2.x Sep 17, 2026
850 of 887 checks passed
@staabm

staabm commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

thank you!

@mlocati
mlocati deleted the redis-array-options-type branch September 17, 2026 13:24
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.

4 participants