December 6, 2019 Javier Eguiluz

The Console component is one of the most popular and mature Symfony components. Even if some developers consider it already feature-complete, in each new Symfony version we add some small new features to it.

Make it mandatory to return the command exit status¶ Contributed by

Jan Schädlich

in #33775. The exit status is a number passed to the parent process (or caller) when a process or command has finished executing its task. A 0 exit status means that the command run successfully and any other number means some error. However, in Symfony commands it's common to not return this exit status. In fact, it's common to not return anything from the execute() command: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // src/Command/CreateUserCommand.php namespace App\Command ; use Symfony\Component\Console\Command\Command ; use Symfony\Component\Console\Input\InputInterface ; use Symfony\Component\Console\Output\OutputInterface ; class CreateUserCommand extends Command { protected static $defaultName = 'app:create-user' ; // ... protected function execute ( InputInterface $input , OutputInterface $output ) { // ... } } In Symfony 4.4 we've deprecated this behavior and you are encouraged to return an integer with the exit status of your command: 1 2 3 4 5 6 protected function execute ( InputInterface $input , OutputInterface $output ) { // ... return 0 ; } Returning the exit status is mandatory in Symfony 5, so better start adding those returns in your commands so you are ready to upgrade.

Configure the trimming of answers¶ Contributed by

Hamza Amrouche

in #31626. When using the Question Helper to ask questions in the console, the answer input by the user is trimmed automatically. Although this is the most common behavior by far, in some edge-cases this is not desirable. In Symfony 4.4, we've added a new setTrimmable() method so you can change the default behavior: 1 2 3 4 5 6 7 8 9 10 use Symfony\Component\Console\Question\Question ; public function execute ( InputInterface $input , OutputInterface $output ) { $helper = $this -> getHelper ( 'question' ); $question = new Question ( 'What is the secret code?' ); $question -> setTrimmable ( false ); // ... } If the user inputs ' abc 1234 ' , that's exactly the value you'll get, instead of the default abc 1234 value.