fork download
  1. <?php
  2.  
  3. function generator($start, $step) {
  4. if (func_num_args() == 1) {
  5. $step = 1;
  6. }
  7.  
  8. return function() use (&$start, $step) {
  9. return $start += $step;
  10. };
  11. }
  12.  
  13. $counter = generator(2);
  14.  
  15. echo $counter();
  16. echo $counter();
  17. echo $counter();
Success #stdin #stdout #stderr 0.01s 20568KB
stdin
Standard input is empty
stdout
345
stderr
PHP Warning:  Missing argument 2 for generator(), called in /home/ZaYgyz/prog.php on line 13 and defined in /home/ZaYgyz/prog.php on line 3