Skip to content

Conversation

@FeBe95
Copy link
Contributor

@FeBe95 FeBe95 commented Dec 31, 2025

Description

By definition, the range() function will never return an empty array. This PR updates the RangeFunctionReturnTypeExtension to follow this definition for all cases.

Note

PHP 8.3 changed how certain “special” or unusual range() calls are handled, but this does not affect the aforementioned definition.

Example:

range(1, 5, -1); // increasing range with a negative step

Up to PHP 8.2, the interpreter attempted to infer a sensible result (e.g. by normalizing the step). Starting with PHP 8.3, such calls either emit warnings or throw errors instead.

Example

range(1, $someInteger);
  • Before:
    list<int>
  • Now:
    non-empty-list<int>

Implementation

Some return types previously did not use NonEmptyArrayType. This PR applies NonEmptyArrayType to all possible return types of range(), ensuring they differ only in their inner element type.

To avoid duplication, a small helper method getNonEmptyListOfType($type) was introduced and reused across the 9 different return statements.

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