Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array_slice() returns non-empty array for existing offsets and positive limit #3121

Closed
wants to merge 2 commits into from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jun 3, 2024

Comment on lines +56 to +61
if ($offsetType !== null
&& $valueType->hasOffsetValueType($offsetType)->yes()
&& ($limitType === null || IntegerRangeType::fromInterval(1, null)->isSuperTypeOf($limitType)->yes())
) {
return $valueType;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the actual fix.

all changes above are just refactoring.

@staabm staabm marked this pull request as ready for review June 3, 2024 20:01
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

];
assertType("array{'zib', 'zib 2'}", $list);
shuffle($list);
assertType("non-empty-array<0|1, 'zib'|'zib 2'>&list", $list);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this PR can't work as is, because the type after shuffle is already not precise enough.

at this point we don't know anymore, that all keys will always exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implemented a more generic approach with #3124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants