Skip to content

Commit

Permalink
File::getMethodParameters(): fix incorrect $typeHintEndToken
Browse files Browse the repository at this point in the history
Given the following code sample:
```php
function foo( ?bool $a, $b ) {}
```

In the resulting array, the second parameter `$b` will have the 'type_hint_end_token' set to the stack pointer for the end of the type declaration for `$a`.

Caused by the `$typeHintEndToken` not being reset for the next parameter.

I've re-ordered the variable reset now to be the same as the order used for the initial variable declarations before the loop to make it more obvious.

While not necessarily a bug, the `$currVar` variable was also not being reset. That's also been fixed now.

I've not added a unit test as the existing tests do not check the token positions in the array.
  • Loading branch information
jrfnl committed Nov 10, 2019
1 parent 200eae5 commit 1b96fdb
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Files/File.php
Expand Up @@ -1496,16 +1496,18 @@ public function getMethodParameters($stackPtr)
}

// Reset the vars, as we are about to process the next parameter.
$defaultStart = null;
$equalToken = null;
$paramStart = ($i + 1);
$passByReference = false;
$referenceToken = false;
$variableLength = false;
$variadicToken = false;
$typeHint = '';
$typeHintToken = false;
$nullableType = false;
$currVar = null;
$paramStart = ($i + 1);
$defaultStart = null;
$equalToken = null;
$passByReference = false;
$referenceToken = false;
$variableLength = false;
$variadicToken = false;
$typeHint = '';
$typeHintToken = false;
$typeHintEndToken = false;
$nullableType = false;

$paramCount++;
break;
Expand Down

0 comments on commit 1b96fdb

Please sign in to comment.