Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] Helper instances should be new for each Command #21417

Copy link
Copy link
Closed
@wjaspers

Description

@wjaspers
Issue body actions

Previously, #14505 highlighted the same issue I am experiencing. However, I believe the issue closed prematurely because it attempted to change the behavior of Command.

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.x.x, 3.x.x
Affected Helpers Progress, Table

Because the Application is a shared instance amongst Console Commands, and the HelperSet is generated from it, all Console Commands share the same default helpers.

This has the unintended side-effect of triggering errors or exceptions when one command may call another, and both use the same Helpers.

For example:

<?php

class CommandA extends \Symfony\Component\Console\Command\Command {
...
protected $name = 'command-a';

public function execute(InputInterface $input, OutputInterface $output) {
  $progress = $this->getHelperSet()->get('progress');
  $progress->start($output, 10);
  $progress->advance();
  $progress->finish();
  return 0;
}
...
}

class CommandB extends \Symfony\Component\Console\Command\Command {
...
protected $name = 'command-b';
public function execute(InputInterface $input, OutputInterface $output) {
   $commandA =  $this->application->get('command-a');
   $commandA->execute($input, $output);

  $progress = $this->getHelperSet()->get('progress');
  $progress->start($output, 10);
  $progress->advance();
  $progress->finish();
  return 0;
}
...
}

Unless, I specifically call clone $this->getHelperSet()->get('progress'), the same instance is used, which triggers a LogicException.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.