Skip to content

[4.x] Deprecate resolving controller classes without ControllerInterface - #163

Open
Hackwar wants to merge 2 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-controller-resolver-interface
Open

Hackwar wants to merge 2 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-controller-resolver-interface

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

ControllerResolver::resolve() says it resolves "a class name if it implements our ControllerInterface", but any existing class is instantiated and returned as [$obj, 'execute'] without checking the interface or the method (a class without execute() then fails with a TypeError from the callable return type). A string controller that matches a function name resolves to that function before the class lookup, and function_exists() is called with non-string values (null raises a deprecation).

This PR:

  • rejects non-string values that are neither arrays nor objects with the usual InvalidArgumentException,
  • looks up class names before function names,
  • throws InvalidArgumentException when the resolved [$instance, 'execute'] is not callable,
  • triggers a deprecation (trigger_deprecation('joomla/application', …)) when the class does not implement Joomla\Controller\ControllerInterface. A follow-up 5.x PR turns this into an exception.

Route definitions are developer-controlled, so the impact is limited.

Behaviour change in 4.x: a string that is both a class and a function name now resolves to the class.

Testing Instructions

New tests in ControllerResolverTest: class before same-named function (new stub SameNameController.php declares both), the deprecation for a class without the interface (new stub PlainController), a class without execute(), and a null controller. The first three fail without the change in src/.

Documentation Changes Required

docs/routing-and-controllers.md: the resolution order table, the failure cases and a deprecation note. The 5.x update guide entry comes with the 5.x PR that removes the fallback.

🤖 Generated with Claude Code

Hackwar and others added 2 commits November 12, 2026 23:10
ControllerResolver resolved any existing class name to [$instance,
'execute'] although it is documented to resolve ControllerInterface
classes; a class without execute() then failed with a TypeError from the
callable return type. A string matching a function name resolved to that
function before the class lookup, and function_exists() was called with
non-string values.

Non-string values are now rejected up front, class names are looked up
before function names, a class without a callable execute() raises the
usual InvalidArgumentException, and resolving a class that does not
implement ControllerInterface triggers a deprecation (to become an
exception in 5.0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the lowest dependencies the PHPUnit bridge handles deprecations
itself, so PHPUnit's deprecation expectation never saw it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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