| Subject |
Details |
| Rector version |
v0.6.0 |
| PHP version |
PHP 7.3.12 |
| Full Command |
composer/bin/rector process rector/test.php -vvv |
Current Behaviour
AddDefaultValueForUndefinedVariableRector rector is re-assigning $this inside a bound closure.
Rector v0.6.0
Config file: rector.yaml
[parsing] rector/test.php
[refactoring] rector/test.php
[applying] Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector
[printing] rector/test.php
1 file with changes
===================
1) rector/test.php
---------- begin diff ----------
--- Original
+++ New
@@ -3,6 +3,7 @@
private $val = 2;
}
$fn = function() {
+ $this = null;
return $this->val;
};
----------- end diff -----------
Applied rules:
* Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector
Minimal PHP Code Causing Issue
<?php
class A {
private $val = 2;
}
$fn = function() {
return $this->val;
};
$closure = Closure::bind($fn, new A(), 'A');
echo $closure(), "\n";
Expected Behaviour
Rector should not attempt to initialize$this
Current Behaviour
AddDefaultValueForUndefinedVariableRectorrector is re-assigning$thisinside a bound closure.Minimal PHP Code Causing Issue
Expected Behaviour
Rector should not attempt to initialize
$this