diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 6349e17f..d08b7f23 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2963,10 +2963,12 @@ class CompilerBase extends \PhpAot\Core\Translator return $tmpVar; } - protected function convertToRef(NodeAbstract $expr): string { + protected function convertToRef(NodeAbstract $expr): string + { $this->checkLeftValue($expr); - if ($this->isVarExpr($expr) and $this->isNativeType($this->parseIdentifier($expr))) { - $this->fatalError($expr, 'Cannot convert variable of native type to reference'); + $var = $this->parseIdentifier($expr); + if ($this->isVarExpr($expr) and $this->isNativeType($var)) { + $this->localVars[$var] = self::TYPE_VAR; } return $this->parseIdentifier($expr) . '.toReference()'; } diff --git a/tests/zend/closures/closure_003.phpt b/tests/zend/closures/closure_003.phpt new file mode 100644 index 00000000..b224a50c --- /dev/null +++ b/tests/zend/closures/closure_003.phpt @@ -0,0 +1,34 @@ +--TEST-- +Closure 003: Lambda with lexical variables (local scope) +--FILE-- + +--EXPECT-- +4 +4 +4 +5 +Done diff --git a/tests/zend/closures/closure_004.phpt b/tests/zend/closures/closure_004.phpt new file mode 100644 index 00000000..236e54b1 --- /dev/null +++ b/tests/zend/closures/closure_004.phpt @@ -0,0 +1,37 @@ +--TEST-- +Closure 004: Lambda with lexical variables (scope lifetime) +--FILE-- + +--EXPECT-- +4 +4 +4 +5 +Done