Skip to content

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

Open
stupalov wants to merge 1 commit into
flightphp:masterfrom
stupalov:fix/dispatcher-function-name-string
Open

stupalov wants to merge 1 commit into
flightphp:masterfrom
stupalov:fix/dispatcher-function-name-string

Conversation

@stupalov

Copy link
Copy Markdown

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>
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