Bug Report
| Subject |
Details |
| Rector version |
last dev-main |
| Installed as |
composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/73087b1a-e21b-4495-b79a-8534ddb1fe84
<?php
class Foo {
public $bar = 1;
}
$name = "bar";
$new_value = 42;
$foo = new Foo();
$func = fn() => ($foo->{$name} = $new_value);
Responsible rules
ArrowFunctionToAnonymousFunctionRector
Actual Behavior
- $func = fn() => ($foo->{$name} = $new_value);
+ $func = function () use ($foo, $name) {
+ return $foo->{$name} = $new_value;
+ };
PHP Warning: Undefined variable $new_value in [...]
Expected Behavior
- $func = fn() => ($foo->{$name} = $new_value);
+ $func = function () use ($foo, $name, $new_value) {
+ return $foo->{$name} = $new_value;
+ };
The transpilation does not include the $new_value variable in the closure use statement, making it null inside the transpiled anonymous function, effectively setting the property to null instead of the expected value from $new_value when executing the function.
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.com/demo/73087b1a-e21b-4495-b79a-8534ddb1fe84
Responsible rules
ArrowFunctionToAnonymousFunctionRectorActual Behavior
Expected Behavior
The transpilation does not include the
$new_valuevariable in the closureusestatement, making itnullinside the transpiled anonymous function, effectively setting the property tonullinstead of the expected value from$new_valuewhen executing the function.