curt Wed Oct 27 22:50:22 2004 EDT
Modified files:
/phpdoc/en/language/oop5 iterations.xml
Log:
Fixed for bug #30588, changed wording and provide an example.
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/iterations.xml?r1=1.8&r2=1.9&ty=u
Index: phpdoc/en/language/oop5/iterations.xml
diff -u phpdoc/en/language/oop5/iterations.xml:1.8
phpdoc/en/language/oop5/iterations.xml:1.9
--- phpdoc/en/language/oop5/iterations.xml:1.8 Sun Oct 17 19:56:31 2004
+++ phpdoc/en/language/oop5/iterations.xml Wed Oct 27 22:50:22 2004
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.8 $ -->
+<!-- $Revision: 1.9 $ -->
<sect1 id="language.oop5.iterations">
<title>Object Iteration</title>
<para>
- PHP 5 provides a way for objects to be defined so it is possible
- to iterate through a list of items, with, for example a <link
- linkend="control-structures.foreach">foreach</link> statement. By default, all
- public properties will be used for the iteration.
+
+ PHP 5 provides a way for objects to be defined so it is possible to iterate
+ through a list of items, with, for example a <link
+ linkend="control-structures.foreach">foreach</link> statement. By default,
+ all <link linkend="oop5.visibility">visible</link> properties will be used
+ for the iteration.
+
</para>
<example>
@@ -20,8 +23,15 @@
public $var2 = 'value 2';
public $var3 = 'value 3';
- protected $protected = 'protected';
- private $private = 'private';
+ protected $protected = 'protected var';
+ private $private = 'private var';
+
+ function iterateVisible() {
+ echo "MyClass::iterateVisible:\n";
+ foreach($this as $key => $value) {
+ print "$key => $value\n";
+ }
+ }
}
$class = new MyClass();
@@ -29,6 +39,11 @@
foreach($class as $key => $value) {
print "$key => $value\n";
}
+echo "\n"
+
+
+$class->iterateVisible();
+
?>
]]>
</programlisting>
@@ -38,18 +53,27 @@
var1 => value 1
var2 => value 2
var3 => value 3
+
+MyClass::iterateVisible:
+var1 => value 1
+var2 => value 2
+var3 => value 3
+protected => protected var
+private => private var
]]>
</screen>
</example>
<para>
- As the output shows, the <link linkend="control-structures.foreach">foreach</link>
- iterated through each public variable that is defined. To take it
- a step further you can <varname>implement</varname> one of PHP 5's
- internal <link linkend="language.oop5.interfaces">interface</link> named
- <varname>Iterator</varname>. This allows the object to decide what
- and how the object will be iterated.
+ As the output shows, the <link
+ linkend="control-structures.foreach">foreach</link> iterated through all
+ <link linkend="oop5.visibility">visible</link> variables that can be
+ accessed. To take it a step further you can <varname>implement</varname> one
+ of PHP 5's internal <link
+ linkend="language.oop5.interfaces">interface</link> named
+ <varname>Iterator</varname>. This allows the object to decide what and how
+ the object will be iterated.
</para>
<example>