Ben büyük, eski bir proje refactor çalışıyorum ve ben fark ettik bir şey farklı Iterator uygulamaları bir aralığı:
while($iterator->moveNext()) {
$item = $iterator->current();
// do something with $item;
}
for($iterator = getIterator(), $iterator->HasNext()) {
$item = $iterator->Next();
// do something with $item
}
while($item = $iterator->fetch()) {
// do something with item
}
veya izin bile StandardPHPLibrary (SPL) yineleyici
foreach($iterator as $item) {
// do something with $item
}
Having so many different Iterators (with different methods for looping over collections) seems like a strong code smell, and I'm inclined to refactor everything to SPL. Is there a compelling advantage to any of these implementations of Iterator, or is it purely a matter of personal taste?