Skip to content

Commit 62b5259

Browse files
committed
Flag stdClass::__construct() calls that have arguments
Fixes #10018
1 parent f40e23f commit 62b5259

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php

+11
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ public static function analyze(
244244
new Union([$result_atomic_type]),
245245
);
246246

247+
if (strtolower($fq_class_name) === 'stdclass' && $stmt->getArgs() !== []) {
248+
IssueBuffer::maybeAdd(
249+
new TooManyArguments(
250+
'stdClass::__construct() has no parameters',
251+
new CodeLocation($statements_analyzer->getSource(), $stmt),
252+
'stdClass::__construct',
253+
),
254+
$statements_analyzer->getSuppressedIssues(),
255+
);
256+
}
257+
247258
if (strtolower($fq_class_name) !== 'stdclass' &&
248259
$codebase->classlikes->classExists($fq_class_name)
249260
) {

tests/MethodCallTest.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ public function x(): void {}
12381238
}
12391239
class Child1 extends Old {}
12401240
class Child2 extends Old {}
1241-
1241+
12421242
/**
12431243
* @template IsClient of bool
12441244
*/
@@ -1798,6 +1798,13 @@ public function foo(callable $_a = "strlen"): void {}
17981798
',
17991799
'error_message' => 'InvalidParamDefault',
18001800
],
1801+
'stdClassConstructorHasNoParameters' => [
1802+
'code' => <<<'PHP'
1803+
<?php
1804+
$a = new stdClass(5);
1805+
PHP,
1806+
'error_message' => 'TooManyArguments',
1807+
],
18011808
];
18021809
}
18031810
}

0 commit comments

Comments
 (0)