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

Using a class-string to construct fails to trigger TooFewArguments #11226

Open
still-dreaming-1 opened this issue Jan 30, 2025 · 1 comment
Open
Labels

Comments

@still-dreaming-1
Copy link
Contributor

https://psalm.dev/r/2b0238bf51

When using a class-string to construct while missing a parameter, Psalm fails to report the TooFewArguments issue.

Here is some very similar code that shows the expected TooFewArguments issue https://psalm.dev/r/4b2ded22f6

Copy link

I found these snippets:

https://psalm.dev/r/2b0238bf51
<?php

/**
 * @psalm-consistent-constructor
 */
class A
{
    final public function __construct(public int $val) {
    }
}

/**
 * @return class-string<A>
 */
function getClass(): string {
    return A::class;
}

$aStr =  getClass(); // A::class;
$obj = new $aStr();
echo $obj->val;
Psalm output (using commit c7c5a69):

No issues!
https://psalm.dev/r/4b2ded22f6
<?php

/**
 * @psalm-consistent-constructor
 */
class A
{
    final public function __construct(public int $val) {
    }
}

$aStr =  A::class;
$obj = new $aStr();
echo $obj->val;
Psalm output (using commit c7c5a69):

ERROR: TooFewArguments - 13:8 - Too few arguments for A::__construct - expecting val to be passed

@orklah orklah added the bug label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants