8000 [Console] Wrong documentation about section() · Issue #9927 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content
[Console] Wrong documentation about section() #9927
Closed
@Aerendir

Description

@Aerendir

The documentation about Console Sections is wrong.

The documentation uses this example:

class MyCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $section1 = $output->section();
        $section2 = $output->section();
        $section1->writeln('Hello');
        $section2->writeln('World!');
        // Output displays "Hello\nWorld!\n"

        // overwrite() replaces all the existing section contents with the given content
        $section1->overwrite('Goodbye');
        // Output now displays "Goodbye\nWorld!\n"

        // clear() deletes all the section contents...
        $section2->clear();
        // Output now displays "Goodbye\n"

        // ...but you can also delete a given number of lines
        // (this example deletes the last two lines of the section)
        $section1->clear(2);
        // Output is now completely empty!
    }
}

The problem is that the interface OutputInterface doesn't have any section() method.

The section() method, instead, is in ConsoleOutputInterface.

I don't know why it is a DocComment and not a real method, but anyway, the examples of the documentation are wrong, as the interface to use is ConsoleOutputInterface and not OutputInterface.

The problem is that type hinting the execute() method with the interface ConsoleOutputInterface is not allowed by PHP.

I don't know where this should be discussed, but is something that should be addressed as to use the section() method someone has to dig in the code to understand where this method is.

This is the PR that updated the documentation: #9462

The same "errors" are also in the blog post that announced the new feature: https://symfony.com/blog/new-in-symfony-4-1-advanced-console-output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0