Skip to content

Commit e8f4e6c

Browse files
committed
minor #13027 Fix example with iterable (peterjaap)
This PR was submitted for the 5.0 branch but it was squashed and merged into the 4.4 branch instead (closes #13027). Discussion ---------- Fix example with iterable The old example throws this error; `PHP Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Console\Helper\ProgressBar::iterate() must be iterable, object given` <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 36b6e43 Fix example with iterable
2 parents a423250 + 36b6e43 commit e8f4e6c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

components/console/helpers/progressbar.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ which starts, advances and finishes the progress bar automatically::
110110

111111
$progressBar = new ProgressBar($output);
112112

113-
// $iterable can be for example an array ([1, 2, 3, ...]) or a generator
114-
// $iterable = function () { yield 1; yield 2; ... };
113+
// $iterable can be for example an array ([1, 2, 3, ...])
114+
$iterable = [1, 2];
115115
foreach ($progressBar->iterate($iterable) as $value) {
116116
// ... do some work
117117
}
118+
119+
// or a generator
120+
function iterable() { yield 1; yield 2; ... };
121+
foreach ($progressBar->iterate(iterable()) as $value) {
122+
// ... do some work
123+
}
118124

119125
If ``$iterable = [1, 2]``, the previous code will output the following:
120126

0 commit comments

Comments
 (0)