Skip to content

Understand at least one argument for non empty array unpacked #4134

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

Merged
merged 2 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ public function check(
$arg->getStartLine(),
];
}

if (count($arguments) === 0 && $type->isIterableAtLeastOnce()->yes()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happen when the constant array is non-empty but all the keys are optional.

$arguments[] = [
$arg->value,
$type->getIterableValueType(),
true,
null,
$arg->getStartLine(),
];
}
} else {
$arguments[] = [
$arg->value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,11 @@ public function testBug8922(): void
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8922.php'], $errors);
}

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

public function testBug13065(): void
{
$errors = [];
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-10020.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Bug10020;

function load(string $path, string ...$extraPaths): void
{
//$this->doLoad(false, \func_get_args());
}

$projectDir = __DIR__;
$environment = 'dev';

$files = array_reverse(array_filter([
$projectDir.'/.env',
$projectDir.'/.env.'.$environment,
$projectDir.'/.env.local',
$projectDir.'/.env.'.$environment.'.local',
], 'file_exists'));

if ($files !== []) {
load(...$files);
}
Loading