[doc-en] master: objects does not have to be Traversable to be ForEach'ed. (#4535)

From: Date: Tue, 01 Sep 2026 11:24:16 +0000
Subject: [doc-en] master: objects does not have to be Traversable to be ForEach'ed. (#4535)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-23681@lists.php.net to get a copy of this message
Author: divinity76 (divinity76) Committer: GitHub (web-flow) Pusher: lacatoire Date: 2026-09-01T13:24:13+02:00 Commit: https://github.com/php/doc-en/commit/0d9947f2b1f0997cd8ddf80227b632dd5d3f2f92 Raw diff: https://github.com/php/doc-en/commit/0d9947f2b1f0997cd8ddf80227b632dd5d3f2f92.diff objects does not have to be Traversable to be ForEach'ed. (#4535) * objects does not have to be Traversable to be ForEach'ed. fix https://github.com/php/doc-en/issues/4534 * foreach: objects do not have to be Traversable Any object can be iterated. State that an object is traversed over its visible properties by default, next to the existing pointer to Object Iteration, and stop calling the operand an iterable, which is the type alias for array|Traversable. --------- Co-authored-by: Louis-Arnaud <la.catoire@gmail.com> Changed paths: M language/control-structures/foreach.xml Diff: diff --git a/language/control-structures/foreach.xml b/language/control-structures/foreach.xml index 80d32a45dd2e..09e5d1e21096 100644 --- a/language/control-structures/foreach.xml +++ b/language/control-structures/foreach.xml @@ -5,7 +5,7 @@ <?phpdoc print-version-for="foreach"?> <para> The <literal>foreach</literal> construct provides an easy way to - iterate over <type>array</type>s and <interfacename>Traversable</interfacename> objects. + iterate over <type>array</type>s and objects. <literal>foreach</literal> will issue an error when used with a variable containing a different data type or with an uninitialized variable. <informalexample> @@ -26,7 +26,7 @@ foreach (iterable_expression as $key => $value) { </informalexample> </para> <simpara> - The first form traverses the iterable given by + The first form traverses the value given by <literal>iterable_expression</literal>. On each iteration, the value of the current element is assigned to <literal>$value</literal>. </simpara> @@ -40,7 +40,9 @@ foreach (iterable_expression as $key => $value) { and <function>key</function>. </simpara> <simpara> - It is possible to + By default, an object is traversed over the properties that are + <link linkend="language.oop5.visibility">visible</link> from the current + scope. It is possible to <link linkend="language.oop5.iterations">customize object iteration</link>. </simpara>

« previous php.doc.cvs (#23681) next »