PHP-Parser icon indicating copy to clipboard operation
PHP-Parser copied to clipboard

Declare CallLike $args as list

Open staabm opened this issue 8 months ago • 2 comments

having a more precise type helps to prevent false positives when implementing e.g. PHPStan rules

private function findInputTypeIdsInNew(New_ $newExpr, ClassReflection $class, Scope $scope): array
    {
        if (\count($newExpr->args) === 0) {
            // more logic
            return [];
        }

        $firstArg = $newExpr->args[0]; // Offset 0 might not exist on non-empty-array<PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder>.
        if (! $firstArg instanceof Arg) {
            return [];
        }

happens when PHPStan is configured with reportPossiblyNonexistentGeneralArrayOffset

staabm avatar Apr 10 '25 08:04 staabm

This looks fine, but will this cause BC issues? I think people were concerned about that in the past.

nikic avatar Apr 10 '25 20:04 nikic

yes, I had similar feelings when submitting the PR. When in doubt this PR has to wait for the next major version

staabm avatar Apr 11 '25 06:04 staabm

@nikic today I stumbled over this again while working on phpstan-src.

do you think it makes sense merging?

staabm avatar Oct 31 '25 07:10 staabm

alternatively (and more safe) we could re-activate https://github.com/phpstan/phpstan-php-parser to override the signatures in phpstan context

staabm avatar Oct 31 '25 08:10 staabm

do it here instead: https://github.com/phpstan/phpstan-src/pull/4503

staabm avatar Oct 31 '25 10:10 staabm