1--TEST-- 2ZE2 iterators and break 3--SKIPIF-- 4<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> 5--FILE-- 6<?php 7class c_iter implements Iterator { 8 9 private $obj; 10 private $num = 0; 11 12 function __construct($obj) { 13 echo __METHOD__ . "\n"; 14 $this->obj = $obj; 15 } 16 function rewind() { 17 echo __METHOD__ . "\n"; 18 $this->num = 0; 19 } 20 function valid() { 21 $more = $this->num < $this->obj->max; 22 echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n"; 23 return $more; 24 } 25 function current() { 26 echo __METHOD__ . "\n"; 27 return $this->num; 28 } 29 function next() { 30 echo __METHOD__ . "\n"; 31 $this->num++; 32 } 33 function key() { 34 echo __METHOD__ . "\n"; 35 switch($this->num) { 36 case 0: return "1st"; 37 case 1: return "2nd"; 38 case 2: return "3rd"; 39 default: return "???"; 40 } 41 } 42 function __destruct() { 43 echo __METHOD__ . "\n"; 44 } 45} 46 47class c implements IteratorAggregate { 48 49 public $max = 3; 50 51 function getIterator() { 52 echo __METHOD__ . "\n"; 53 return new c_iter($this); 54 } 55 function __destruct() { 56 echo __METHOD__ . "\n"; 57 } 58} 59 60$t = new c(); 61 62foreach($t as $k => $v) { 63 foreach($t as $w) { 64 echo "double:$v:$w\n"; 65 break; 66 } 67} 68 69unset($t); 70 71print "Done\n"; 72?> 73--EXPECT-- 74c::getIterator 75c_iter::__construct 76c_iter::rewind 77c_iter::valid = true 78c_iter::current 79c_iter::key 80c::getIterator 81c_iter::__construct 82c_iter::rewind 83c_iter::valid = true 84c_iter::current 85double:0:0 86c_iter::__destruct 87c_iter::next 88c_iter::valid = true 89c_iter::current 90c_iter::key 91c::getIterator 92c_iter::__construct 93c_iter::rewind 94c_iter::valid = true 95c_iter::current 96double:1:0 97c_iter::__destruct 98c_iter::next 99c_iter::valid = true 100c_iter::current 101c_iter::key 102c::getIterator 103c_iter::__construct 104c_iter::rewind 105c_iter::valid = true 106c_iter::current 107double:2:0 108c_iter::__destruct 109c_iter::next 110c_iter::valid = false 111c_iter::__destruct 112c::__destruct 113Done 114