Symfony

Console & Commands

Custom commands, arguments, options, output styling, interactive commands, progress bars

18 interview questionsยท
Mid-Level
1

Which base class should be extended to create a custom console command in Symfony?

Answer

To create a console command in Symfony, the Command class from the Console component must be extended. This class provides all necessary methods to define the command name, description, arguments and options, as well as the execute() method containing the business logic. The #[AsCommand] attribute allows declarative command configuration.

2

Which PHP attribute allows configuring a Symfony command declaratively since PHP 8?

Answer

The #[AsCommand] attribute introduced in Symfony 6 allows declarative command configuration. It accepts the command name as the first argument and optionally a description. This replaces configuration in the configure() method for basic information, making code more readable and concise while still allowing configure() for more complex configurations.

3

What is the fundamental difference between an argument and an option in a Symfony console command?

Answer

An argument is a positional value, required or optional, passed directly after the command name (e.g., app:user:create john). An option is prefixed with -- (or -) and can have a value or be a boolean flag (e.g., --verbose, --format=json). Arguments are ordered and identified by position, while options can appear in any order.

4

Which method of the command contains the main logic to execute?

5

How to define a required argument in a Symfony command?

+15 interview questions

Master Symfony for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free