1
2<?php
3class MyClass
4{
5 public $var1 = 'value 1';
6 public $var2 = 'value 2';
7 public $var3 = 'value 3';
8
9 protected $protected = 'protected var';
10 private $private = 'private var';
11
12 function iterateVisible() {
13 echo "MyClass::iterateVisible:\n";
14 foreach ($this as $key => $value) {
15 print "$key => $value\n";
16 }
17 }
18}
19
20$class = new MyClass();
21
22foreach($class as $key => $value) {
23 print "$key => $value\n";
24}
25echo "\n";
26
27
28$class->iterateVisible();
29
30?>
31
32