Skip to content

Commit 074de75

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Treat get_defined_vars() as using function arguments
1 parent 1453c3f commit 074de75

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Rules/UnusedFunctionParametersCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private function getUsedVariables(Scope $scope, $node): array
6363
if ($node instanceof Node) {
6464
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
6565
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
66-
if ($functionName === 'func_get_args') {
66+
if ($functionName === 'func_get_args' || $functionName === 'get_defined_vars') {
6767
return $scope->getDefinedVariables();
6868
}
6969
}

tests/PHPStan/Rules/Classes/UnusedConstructorParametersRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ public function testBug1917(): void
4343
$this->analyse([__DIR__ . '/data/bug-1917.php'], []);
4444
}
4545

46+
public function testBug10865(): void
47+
{
48+
$this->analyse([__DIR__ . '/data/bug-10865.php'], []);
49+
}
50+
4651
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Bug10865;
4+
5+
class TestParent {
6+
7+
/** @param array<string|int, mixed> $args */
8+
public function __construct(array $args) {
9+
10+
var_dump($args);
11+
}
12+
}
13+
14+
class Test extends TestParent {
15+
16+
public function __construct(int $a) {
17+
18+
parent::__construct(get_defined_vars());
19+
//parent::__construct(func_get_args());
20+
}
21+
}

0 commit comments

Comments
 (0)