1--TEST--
2Foreach loop tests - Removing the current element from an iterated object.
3--FILE--
4<?php
5
6class C {
7    public $a = "Original a";
8    public $b = "Original b";
9    public $c = "Original c";
10    public $d = "Original d";
11    public $e = "Original e";
12}
13
14echo "\nRemoving the current element from an iterated object.\n";
15$obj = new C;
16$count=0;
17foreach ($obj as $v) {
18    if ($v==$obj->b) {
19        unset($obj->b);
20    }
21    var_dump($v);
22    if (++$count>10) {
23        echo "Loop detected.\n";
24        break;
25    }
26}
27var_dump($obj);
28
29
30?>
31--EXPECTF--
32Removing the current element from an iterated object.
33string(10) "Original a"
34string(10) "Original b"
35
36Warning: Undefined property: C::$b in %s on line %d
37string(10) "Original c"
38
39Warning: Undefined property: C::$b in %s on line %d
40string(10) "Original d"
41
42Warning: Undefined property: C::$b in %s on line %d
43string(10) "Original e"
44object(C)#%d (4) {
45  ["a"]=>
46  string(10) "Original a"
47  ["c"]=>
48  string(10) "Original c"
49  ["d"]=>
50  string(10) "Original d"
51  ["e"]=>
52  string(10) "Original e"
53}
54