Skip to content

fix: allow plain function name callbacks in Dispatcher::execute() - #730

Merged
n0nag0n merged 1 commit into
flightphp:masterfrom
stupalov:fix/dispatcher-function-name-string
Oct 24, 2026
Merged

n0nag0n merged 1 commit into
flightphp:masterfrom
stupalov:fix/dispatcher-function-name-string

Conversation

@stupalov

Copy link
Copy Markdown
Contributor

Since v3.19.2 (cbc1cb3, part of #721), Dispatcher::execute() passes every string callback to parseStringClassAndMethod(), so a route or event mapped to a plain global function name no longer works:

function hello($name) { echo "hello $name"; }

Flight::route('/hello/@name', 'hello');
// InvalidArgumentException: Invalid string format 'hello', use 'ClassName::method' or 'ClassName->method'.

verifyValidFunction() still lists 'existingFunction' as a valid callable, and up to v3.19.1 execute() only parsed strings containing -> or ::, so this looks like an unintended regression. We hit it on upgrade: our whole API registers routes by function name.

The fix calls an existing function name directly and leaves Class->method / Class::method strings on the existing parse path, so Class::nonStaticMethod is still instantiated as before, including on PHP 7.4 where is_callable() would accept it as a static call.

Added DispatcherTest::testExecuteGlobalFunctionString; it fails on v3.19.4 with the exception above.

Checked locally: phpunit on PHP 7.4.33 and 8.5.10 (501 tests), phpcs clean on the changed files, phpstan reports the same errors as on v3.19.4 (nothing new). I did not run composer test-server.

🤖 Generated with Claude Code

Since v3.19.2 every string callback went through parseStringClassAndMethod(),
so routes and events mapped to a global function name threw
InvalidArgumentException. Call existing functions directly and keep the
Class->method / Class::method parsing as before.

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

ambrose5773 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Nice catch and thanks for the clean fix, stupalov! Keeping the Class::method / Class->method parsing untouched and adding a test that fails on v3.19.4 makes this really easy to review, and thanks for checking 7.4 too. CI is running now, and n0nag0n will take a look for merge. Appreciate you helping keep Flight in good shape!

@n0nag0n
n0nag0n merged commit ca330bc into flightphp:master Oct 24, 2026
21 checks passed
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.

3 participants