Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for variable name in parameters before adding to uses #268

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bryannielsen
Copy link

I hit an issue today in downgrading some Laravel code.
The ArrowFunctionToAnonymousFunctionRector rule would take this function

fn ($deferred) => app(DeferredCallbackCollection::class)[] = $deferred

and transform it to this

function ($deferred) use ($deferred) {
    return app(DeferredCallbackCollection::class)[] = $deferred;
}

and this would result in a PHP error

Fatal error: Cannot use lexical variable $deferred as a parameter name in <file_path>

My patch works well for solving my problem but if there's a better way to fix this that would be great too.
Thanks for your hard work!

@TomasVotruba
Copy link
Member

Hi, thanks for the fix. Could you add also failing test fixture, so we have it covered?

@bryannielsen
Copy link
Author

bryannielsen commented Mar 20, 2025

Sorry about that!
I added the test but the only case that was failing before my patch was singleArrayAssignment which mirrors the situation I hit today.

The rest of the cases all worked properly which surprised me so maybe there is a better/different fix that should be made for that case?

@bryannielsen
Copy link
Author

@TomasVotruba and @samsonasik I don't understand the last failing check but I'm happy to try and resolve it if you can point me in the right direction. Thanks!

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