Skip to content

[4.x] Deprecate naming commands with the static $defaultName property - #40

Open
Hackwar wants to merge 2 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-deprecate-default-name
Open

Hackwar wants to merge 2 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-deprecate-default-name

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Symfony removed Command::$defaultName in 7.0 in favour of the #[AsCommand] attribute, which AbstractCommand reads as well once #38 is merged. This deprecates the static property for removal in 5.0:

  • AbstractCommand::$defaultName gets @deprecated 5.0 Use the #[AsCommand] attribute instead;
  • AbstractCommand::getDefaultName() (and so the constructor) triggers a deprecation via trigger_deprecation('joomla/console', '__DEPLOY_VERSION__', …) when a class names itself through the property; commands using the attribute trigger nothing;
  • the built-in help and list commands use #[AsCommand] instead of the property;
  • symfony/deprecation-contracts (^2|^3, as in the other packages) is added to require for trigger_deprecation().

The property keeps working unchanged in 4.x.

Depends on #38: this branch contains its commit; please review only the last commit ("Deprecate naming commands with the static $defaultName property"). The 5.x removal is a separate PR against 5.x-dev.

Related to #39, which changes the symfony/console line in composer.json right next to the added symfony/deprecation-contracts line — expect a one-line conflict there, keep both changes.

Testing Instructions

  • AbstractCommandTest::testTheDefaultNamePropertyIsDeprecated expects the deprecation for a $defaultName command (fails without this change);
  • AbstractCommandTest::testTheAsCommandAttributeIsNotDeprecated checks that an attribute-only command raises no deprecation;
  • the existing tests for help/list cover the switch to the attribute.

The test fixtures keep using $defaultName in 4.x to show it still works; the deprecation is silenced (@trigger_error) like all Symfony-style deprecations.

Documentation Changes Required

  • docs/overview.md: the paragraph on naming commands says $defaultName is deprecated since 4.1 and not read in 5.0.
  • docs/v3-to-v4-update.md: the 4.1 note mentions the deprecation.
  • The 5.0 update guide entry is part of the 5.x removal PR.

🤖 Generated with Claude Code

Hackwar and others added 2 commits November 13, 2026 01:09
AbstractCommand does not extend Symfony's Command, so a command written
the way the Symfony 7 documentation describes, with #[AsCommand] instead
of the static $defaultName removed from Symfony, had no name and could
not be registered.

getDefaultName() now falls back to the attribute when the class does
not declare $defaultName, and the constructor applies the attribute's
aliases, hidden flag, description and help. $defaultName keeps
precedence. The reflection result is cached per class instead of being
rebuilt on every getDefaultName() call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Symfony removed Command::$defaultName in 7.0 in favour of #[AsCommand],
which AbstractCommand now reads as well. Deprecate the property for
removal in 5.0: getDefaultName() triggers a deprecation when a class
names itself through it. The help and list commands use the attribute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

I would remove this in version 6.0 of the framework and not in 5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant