1--TEST--
2Foreach loop tests - removing properties before and after the current property during the loop.
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 properties before the current element from an iterated object.\n";
15$obj = new C;
16$count=0;
17foreach ($obj as $v) {
18    if ($v==$obj->a) {
19        unset($obj->c);
20    }
21    var_dump($v);
22    if (++$count>10) {
23        echo "Loop detected.\n";
24        break;
25    }
26}
27var_dump($obj);
28
29echo "\nRemoving properties before the current element from an iterated object.\n";
30$obj = new C;
31foreach ($obj as $v) {
32    if ($v==$obj->b) {
33        unset($obj->a);
34    }
35    var_dump($v);
36    if (++$count>10) {
37        echo "Loop detected.\n";
38        break;
39    }
40}
41var_dump($obj);
42
43
44?>
45--EXPECTF--
46Removing properties before the current element from an iterated object.
47string(10) "Original a"
48string(10) "Original b"
49string(10) "Original d"
50string(10) "Original e"
51object(C)#%d (4) {
52  ["a"]=>
53  string(10) "Original a"
54  ["b"]=>
55  string(10) "Original b"
56  ["d"]=>
57  string(10) "Original d"
58  ["e"]=>
59  string(10) "Original e"
60}
61
62Removing properties before the current element from an iterated object.
63string(10) "Original a"
64string(10) "Original b"
65string(10) "Original c"
66string(10) "Original d"
67string(10) "Original e"
68object(C)#%d (4) {
69  ["b"]=>
70  string(10) "Original b"
71  ["c"]=>
72  string(10) "Original c"
73  ["d"]=>
74  string(10) "Original d"
75  ["e"]=>
76  string(10) "Original e"
77}
78