Skip to content

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Aug 11, 2025

Hello!

Closes rectorphp/rector#9302

This converts function and method calls that contain arguments with assignments to named arguments if the variable is not used in subsequent statements. This is a legacy pattern to give insight into the parameter name before named arguments were introduced in PHP 8

-in_array('foo', $array, $strict = true);
+in_array('foo', $array, strict: true);

Thanks!

This converts function and method calls that contain arguments with
assignments to named arguments.
@TomasVotruba
Copy link
Member

Hey,
thanks for proposal.

This could break code as variable is removed.
This rule is better suited for local use only.

@calebdw
Copy link
Contributor Author

calebdw commented Aug 11, 2025

@TomasVotruba, this can't break code because I check to make sure that the variable is not used in the rest of the code prior to removing---I have tests that show this is working

@TomasVotruba
Copy link
Member

Still looks like too niche to be part of core. Every rule we have here is most likely part of default set. That comes with performance hit, so rules must be practical in the wild, no to slow down run for near-zero gain.

@calebdw
Copy link
Contributor Author

calebdw commented Aug 11, 2025

So you're saying that you've never seen this legacy pattern in other codebases and have manually converted them to named arguments? These are variables that aren't used anywhere else and is just like using foo(/* some_parameter */ 42); in C because it doesn't have named parameters.

Would you be willing to accept this if was removed from the PHP 8 set and instead had to manually be included by the user?

If not that's fine, but I'm tried of seeing this pattern and having to manually update in my work codebase, and I can't imagine that I'm the only one

@github-actions
Copy link
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add rector to convert assigns to named arguments

2 participants