Skip to content

Return type of RecursiveDirectoryIterator::getChildren() is too wide #42468

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

Closed
derrabus opened this issue Aug 10, 2021 · 0 comments · Fixed by #42736
Closed

Return type of RecursiveDirectoryIterator::getChildren() is too wide #42468

derrabus opened this issue Aug 10, 2021 · 0 comments · Fixed by #42736

Comments

@derrabus
Copy link
Member

Symfony version(s) affected: 5.3

Description
PHP 8.1 adds tentative return types and triggers deprecation warnings if the return types of our implementations are missing or incompatible. We can add a ReturnTypeWillChange attribute to suppress the deprecation, but we should eventually remove it and replace it with an actual return type. This is what PR #42378 does.

Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator overrides the core class RecursiveDirectoryIterator. The core class declares the following return type:

public function getChildren(): \RecursiveDirectoryIterator

This is a problem because our implementation under certain circumstances returns RecursiveArrayIterator because of that, the return type that we would need to declare would not be covariant to the return type of the core function.

How to reproduce
https://github.com/symfony/symfony/runs/3293455759?check_suite_focus=true#step:8:191

Possible Solution
Change the implementation of getChildren() so that it always returns instances of RecursiveDirectoryIterator.

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