Large collection copy (ARCH7086)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key php.performance.large-collection-copy · Severity info · Category performance
Dumping an entire generator into an array with iterator_to_array() loads all the data into memory. If you only stream over it, iterate the generator directly.
Incorrect
Section titled “Incorrect”<?phpfunction sumLines(\Generator $lines): int{ $all = iterator_to_array($lines); return array_sum($all);}Correct
Section titled “Correct”<?phpfunction sumLines(\Generator $lines): int{ $total = 0; foreach ($lines as $line) { $total += $line; } return $total;}Stream over the generator instead of materializing data you only iterate once into an array.