Skip to content

Commit 663e817

Browse files
authored
Section method only in ConsoleOutputInterface
Since `excecute()` accepts an instanceof `OutputInterface` which does't contains the method (`section`)[https://github.com/symfony/symfony/blob/5.0/src/Symfony/Component/Console/Output/ConsoleOutputInterface.php#L31] we have to add a check on `ConsoleOutputInterface`
1 parent 23ed1d4 commit 663e817

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

console.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,14 @@ which returns an instance of
195195
{
196196
protected function execute(InputInterface $input, OutputInterface $output)
197197
{
198-
$section1 = $output->section();
199-
$section2 = $output->section();
198+
// section() method available only in classes implement ConsoleOutputInterface
199+
if ($output instanceof ConsoleOutputInterface) {
200+
$section1 = $output->section();
201+
$section2 = $output->section();
202+
} else {
203+
$section1 = $section2 = $output;
204+
}
205+
200206
$section1->writeln('Hello');
201207
$section2->writeln('World!');
202208
// Output displays "Hello\nWorld!\n"

0 commit comments

Comments
 (0)