Skip to content

Commit

Permalink
File::isReference(): bug fix - closure return by reference not recogn…
Browse files Browse the repository at this point in the history
…ized

The `&` in a closure declared to return by reference was not recognized as a reference.

Fixed now.

Includes unit test.
  • Loading branch information
jrfnl committed May 31, 2020
1 parent 75ff420 commit 1ae9566
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,7 @@ public function isReference($stackPtr)
);

if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION
|| $this->tokens[$tokenBefore]['code'] === T_CLOSURE
|| $this->tokens[$tokenBefore]['code'] === T_FN
) {
// Function returns a reference.
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/File/IsReferenceTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ $closure = function() use (&$var){};

/* testArrowFunctionReturnByReference */
fn&($x) => $x;

/* testClosureReturnByReference */
$closure = function &($param) use ($value) {};
4 changes: 4 additions & 0 deletions tests/Core/File/IsReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public function dataIsReference()
'/* testArrowFunctionReturnByReference */',
true,
],
[
'/* testClosureReturnByReference */',
true,
],
];

}//end dataIsReference()
Expand Down

0 comments on commit 1ae9566

Please sign in to comment.