Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat get_defined_vars() as using function arguments #3012

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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());
}
}