Lab 04: Generators Advanced
Step 1: Generator Basics Recap
<?php
function fibonacci(): \Generator {
[$a, $b] = [0, 1];
while (true) {
yield $a;
[$a, $b] = [$b, $a + $b];
}
}
$fib = fibonacci();
for ($i = 0; $i < 10; $i++) {
echo $fib->current() . ' ';
$fib->next();
}
echo "\n";Step 2: Generator Delegation — yield from
yield fromStep 3: Bidirectional Generators — send()
send()Step 4: getReturn() from Generators
getReturn() from GeneratorsStep 5: Lazy Evaluation Pipeline
Step 6: Memory Comparison — Array vs Generator
Step 7: Generator-Based File Processing
Step 8: Capstone — Infinite Data Stream with Windowing
Summary
Feature
Syntax
Use Case
Last updated
