@@ -125,7 +125,7 @@ protected function enclose($result, $node, $signature, $static, $emit) {
125
125
$ capture = [];
126
126
foreach ($ result ->codegen ->search ($ node , 'variable ' ) as $ var ) {
127
127
if (isset ($ result ->locals [$ var ->pointer ])) {
128
- $ capture [$ var ->pointer ]= true ;
128
+ $ capture [$ var ->pointer ]??= ( $ result -> locals [ $ var -> pointer ] ? ' &$ ' : ' $ ' ). $ var -> pointer ;
129
129
}
130
130
}
131
131
unset($ capture ['this ' ]);
@@ -143,9 +143,9 @@ protected function enclose($result, $node, $signature, $static, $emit) {
143
143
}
144
144
145
145
if ($ capture ) {
146
- $ result ->out ->write ('use($ ' .implode (', $ ' , array_keys ( $ capture) ).') ' );
147
- foreach ($ capture as $ name => $ _ ) {
148
- $ result ->locals [$ name ]= true ;
146
+ $ result ->out ->write ('use( ' .implode (', ' , $ capture ).') ' );
147
+ foreach ($ capture as $ name => $ variable ) {
148
+ $ result ->locals [$ name ]= ' & ' === $ variable [ 0 ] ;
149
149
}
150
150
}
151
151
@@ -298,7 +298,7 @@ protected function emitArray($result, $array) {
298
298
}
299
299
300
300
protected function emitParameter ($ result , $ parameter ) {
301
- $ result ->locals [$ parameter ->name ]= true ;
301
+ $ result ->locals [$ parameter ->name ]= $ parameter -> reference ;
302
302
$ parameter ->annotations && $ this ->emitOne ($ result , $ parameter ->annotations );
303
303
304
304
// If we have a non-constant default and a type, emit a nullable type hint
@@ -340,7 +340,7 @@ protected function emitSignature($result, $signature, $use= null) {
340
340
if ($ use ) {
341
341
$ result ->out ->write (' use( ' .implode (', ' , $ use ).') ' );
342
342
foreach ($ use as $ variable ) {
343
- $ result ->locals [substr ($ variable , 1 )]= true ;
343
+ $ result ->locals [ltrim ($ variable , ' &$ ' )]= ' & ' === $ variable [ 0 ] ;
344
344
}
345
345
}
346
346
@@ -675,7 +675,7 @@ protected function emitProperty($result, $property) {
675
675
676
676
protected function emitMethod ($ result , $ method ) {
677
677
$ locals = $ result ->locals ;
678
- $ result ->locals = ['this ' => true ];
678
+ $ result ->locals = ['this ' => false ];
679
679
$ meta = [
680
680
DETAIL_RETURNS => $ method ->signature ->returns ? $ method ->signature ->returns ->name () : 'var ' ,
681
681
DETAIL_ANNOTATIONS => $ method ->annotations ,
@@ -798,7 +798,7 @@ protected function emitOffset($result, $offset) {
798
798
protected function emitAssign ($ result , $ target ) {
799
799
if ($ target instanceof Variable && $ target ->const ) {
800
800
$ result ->out ->write ('$ ' .$ target ->pointer );
801
- $ result ->locals [$ target ->pointer ]= true ;
801
+ $ result ->locals [$ target ->pointer ]= false ;
802
802
} else if ($ target instanceof ArrayLiteral) {
803
803
$ result ->out ->write ('[ ' );
804
804
foreach ($ target ->values as $ pair ) {
0 commit comments