diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php index 1a9daef9f..1dbf40420 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php @@ -244,6 +244,17 @@ final class NewAnalyzer extends CallAnalyzer new Union([$result_atomic_type]), ); + if (strtolower($fq_class_name) === 'stdclass' && $stmt->getArgs() !== []) { + IssueBuffer::maybeAdd( + new TooManyArguments( + 'stdClass::__construct() has no parameters', + new CodeLocation($statements_analyzer->getSource(), $stmt), + 'stdClass::__construct', + ), + $statements_analyzer->getSuppressedIssues(), + ); + } + if (strtolower($fq_class_name) !== 'stdclass' && $codebase->classlikes->classExists($fq_class_name) ) { diff --git a/tests/MethodCallTest.php b/tests/MethodCallTest.php index fa56564e7..49eebbf75 100644 --- a/tests/MethodCallTest.php +++ b/tests/MethodCallTest.php @@ -1238,7 +1238,7 @@ class MethodCallTest extends TestCase } class Child1 extends Old {} class Child2 extends Old {} - + /** * @template IsClient of bool */ @@ -1798,6 +1798,13 @@ class MethodCallTest extends TestCase ', 'error_message' => 'InvalidParamDefault', ], + 'stdClassConstructorHasNoParameters' => [ + 'code' => <<<'PHP' + 'TooManyArguments', + ], ]; } }