summaryrefslogtreecommitdiff
path: root/tests/lang/foreachLoopObjects.001.phpt
blob: 7e8a40438edbbda1eadd361cd8011d633599eb51 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--TEST--
Foreach loop on objects - basic loop with just value and key => value.
--FILE--
<?php

class C {
	public $a = "Original a";
	public $b = "Original b";
	public $c = "Original c";
	protected $d = "Original d";
	private $e = "Original e";

}

echo "\n\nSimple loop.\n";
$obj = new C;
foreach ($obj as $v) {
	var_dump($v);
}
foreach ($obj as $k => $v) {
	var_dump($k, $v);
}
echo "\nCheck key and value after the loop.\n";
var_dump($k, $v);


echo "\n\nObject instantiated inside loop.\n";
foreach (new C as $v) {
	var_dump($v);
}
foreach (new C as $k => $v) {
	var_dump($k, $v);
}
echo "\nCheck key and value after the loop.\n";
var_dump($k, $v);
?>
--EXPECT--
Simple loop.
string(10) "Original a"
string(10) "Original b"
string(10) "Original c"
string(1) "a"
string(10) "Original a"
string(1) "b"
string(10) "Original b"
string(1) "c"
string(10) "Original c"

Check key and value after the loop.
string(1) "c"
string(10) "Original c"


Object instantiated inside loop.
string(10) "Original a"
string(10) "Original b"
string(10) "Original c"
string(1) "a"
string(10) "Original a"
string(1) "b"
string(10) "Original b"
string(1) "c"
string(10) "Original c"

Check key and value after the loop.
string(1) "c"
string(10) "Original c"