summaryrefslogtreecommitdiff
path: root/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt
blob: b7c3cf67023d7e47709aaa48b97dd71018a14a61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--TEST--
SPL: RecursiveIteratorIterator::endIteration() is called when ::valid() first returns false
--CREDITS--
Matt Raines matt@raines.me.uk
#testfest London 2009-05-09
--FILE--
<?php
$sample_array = array(1, 2);
$sub_iterator = new RecursiveArrayIterator($sample_array);

$iterator = new RecursiveIteratorIterator($sub_iterator);
foreach ($iterator as $element) {
  var_dump($element);
}

class EndIterationRecursiveIteratorIterator extends RecursiveIteratorIterator {
  public function endIteration() {
    echo "::endIteration() was invoked\n";
  }
}
$iterator = new EndIterationRecursiveIteratorIterator($sub_iterator);
foreach ($iterator as $element) {
  var_dump($element);
}
?>
--EXPECT--
int(1)
int(2)
int(1)
int(2)
::endIteration() was invoked