1--TEST-- 2ZE2 iterators must be implemented 3--SKIPIF-- 4<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> 5--FILE-- 6<?php 7 8echo "1st try\n"; 9 10class c1 {} 11 12$obj = new c1(); 13 14foreach($obj as $w) { 15 echo "object:$w\n"; 16} 17 18echo "2nd try\n"; 19 20class c2 { 21 22 public $max = 3; 23 public $num = 0; 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 valid() { 34 echo __METHOD__ . "\n"; 35 return $this->num < $this->max; 36 } 37 function key() { 38 echo __METHOD__ . "\n"; 39 switch($this->num) { 40 case 0: return "1st"; 41 case 1: return "2nd"; 42 case 2: return "3rd"; 43 default: return "???"; 44 } 45 } 46} 47 48$obj = new c2(); 49 50foreach($obj as $v => $w) { 51 echo "object:$v=>$w\n"; 52} 53 54print "Done\n"; 55?> 56--EXPECTF-- 571st try 582nd try 59object:max=>3 60object:num=>0 61Done 62