Skip to content

fix: return type should be iterable#5443

Closed
develth wants to merge 1 commit into
api-platform:mainfrom
develth:patch-1
Closed

fix: return type should be iterable#5443
develth wants to merge 1 commit into
api-platform:mainfrom
develth:patch-1

Conversation

@develth

@develth develth commented Mar 8, 2023

Copy link
Copy Markdown
Contributor

... to match for example CollectionProvideres return type on pagination

Q A
Branch? main
Tickets
License MIT
Doc PR

... to match for example CollectionProvideres return type on pagination
* @return T|Pagination\PartialPaginatorInterface<T>|iterable<T>|null
*/
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null;
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|iterable|null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that this is breaking compatibility

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But regarding this it's not compatible

public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable

@soyuka

soyuka commented Mar 9, 2023

Copy link
Copy Markdown
Member

we found our reasoning: #5024

@soyuka soyuka closed this Mar 9, 2023
@develth

develth commented Mar 9, 2023

Copy link
Copy Markdown
Contributor Author

@soyuka

FYI object|array is identical to object|iterable even in PHP 8.0 and 8.1. :)

Ok, thought that on the otherview object|iterable is not identical to object|array, because Iteratable also contains Traversable which would not match with array.

Thx for information.

@soyuka

soyuka commented Mar 9, 2023

Copy link
Copy Markdown
Member

Mhh actually it looks like a PHP issue php/php-src@bb79ef7

Iterable is a built-in compile time type alias for array|Traversable. From its introduction in PHP 7.1.0 and prior to PHP 8.2.0, iterable was a built-in pseudo-type that acted as the aforementioned type alias and can be used as a type declaration. An iterable type can be used in foreach and with yield from within a generator.

reopening this

@soyuka soyuka reopened this Mar 9, 2023
@soyuka

soyuka commented Mar 10, 2023

Copy link
Copy Markdown
Member

We need to find out what PHP's choice is for 8.3 if we should revert or not . but basically iterable and array are compatible so it doesn't change much

@stale

stale Bot commented May 9, 2023

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label May 9, 2023
@nesl247

nesl247 commented May 9, 2023

Copy link
Copy Markdown
Contributor

This is still an issue.

@stale stale Bot removed the stale label May 9, 2023
@soyuka

soyuka commented May 22, 2023

Copy link
Copy Markdown
Member

why @nesl247 ?

@nesl247

nesl247 commented May 30, 2023

Copy link
Copy Markdown
Contributor

@soyuka I didn't see any changes made for this. Were there?

@soyuka

soyuka commented May 30, 2023

Copy link
Copy Markdown
Member

why is this a problem?

@nesl247

nesl247 commented May 30, 2023

Copy link
Copy Markdown
Contributor

why is this a problem?

#5303

@soyuka

soyuka commented May 30, 2023

Copy link
Copy Markdown
Member

I don't get the issue as array and iterables should be compatible. Also not sure what PHP's decision is for 8.3. I'm afraid that the fix is wrong regarding the types, when using ProviderInterface<array> you'd get iterable<array> which isn't wanted no?

@stale

stale Bot commented Jul 29, 2023

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Jul 29, 2023
@stale stale Bot closed this Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants