Skip to content

Commit

Permalink
Treat get_defined_vars() as using function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen authored and ondrejmirtes committed Apr 12, 2024
1 parent 1453c3f commit 074de75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rules/UnusedFunctionParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function getUsedVariables(Scope $scope, $node): array
if ($node instanceof Node) {
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
if ($functionName === 'func_get_args') {
if ($functionName === 'func_get_args' || $functionName === 'get_defined_vars') {
return $scope->getDefinedVariables();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public function testBug1917(): void
$this->analyse([__DIR__ . '/data/bug-1917.php'], []);
}

public function testBug10865(): void
{
$this->analyse([__DIR__ . '/data/bug-10865.php'], []);
}

}
21 changes: 21 additions & 0 deletions tests/PHPStan/Rules/Classes/data/bug-10865.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Bug10865;

class TestParent {

/** @param array<string|int, mixed> $args */
public function __construct(array $args) {

var_dump($args);
}
}

class Test extends TestParent {

public function __construct(int $a) {

parent::__construct(get_defined_vars());
//parent::__construct(func_get_args());
}
}

0 comments on commit 074de75

Please sign in to comment.