-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Open
Description
Symfony version(s) affected
6.4.24, 7.3.5, thus probably all ?
Description
When working with Finder, I need to be explicitly sure about type it will provide.
When looking at docs, I see that:
- getIterator() returns
\Iterator<non-empty-string, SplFileInfo> - Finder itself implements
\IteratorAggregate<non-empty-string, SplFileInfo>
Note that this is non-rooted SplFileInfo - which is Symfony\Component\Finder\SplFileInfo in this context. There is no explicit import, as both files are in very same Finder's namespace.
Then, I call the item from the iterator and I got surprised to get \SplFileInfo instead of \Symfony\Component\Finder\SplFileInfo.
Can you clarify what is expected behaviour?
Is it issue somewhere in code, and one shall always get \Symfony\Component\Finder\SplFileInfo ?
Or it's issue in docs, and thus documented type shall be \SplFileInfo ?
How to reproduce
<?php
include 'vendor/autoload.php';
/////
$finder = \Symfony\Component\Finder\Finder::create()
->in(__DIR__)
->append([__FILE__]);
$files = iterator_to_array($finder->getIterator());
var_dump(get_class(array_pop($files))); // \Symfony\Component\Finder\SplFileInfo
/////
$finder = \Symfony\Component\Finder\Finder::create()
->append([__FILE__]);
$files = iterator_to_array($finder->getIterator());
var_dump(get_class(array_pop($files))); // \SplFileInfo , !!!Possible Solution
depends on intention how code should behave
Additional Context
No response