Bug report
PHPStan 2.2.0 crashes with an internal error in Rules/FunctionCallParametersCheck.php:155 when analysing a new self(...$properties) call in a child class whose constructor adds a promoted parameter on top of the parent's, and where $properties is built by iterating over the parent constructor's ReflectionMethod parameters.
The crash only occurs when bleedingEdge.neon is included. Without bleedingEdge, PHPStan reports a normal argument.type error and completes the analysis.
<?php
declare(strict_types=1);
class Event {
public function __construct(public int $a) {}
}
class EventOutput extends Event {
public function __construct(public int $a, public bool $b) {
parent::__construct(a: $a);
}
public static function fromEvent(Event $event, bool $b): self
{
$properties = ['b' => $b];
$construct = new \ReflectionMethod(Event::class, '__construct');
foreach ($construct->getParameters() as $parameter) {
$properties[$parameter->getName()] = $event->{$parameter->getName()};
}
return new self(...$properties);
}
}
Stack trace (top frames)
## phar://.../vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionCallParametersCheck.php(155)
#0 .../Rules/Classes/InstantiationRule.php(176): PHPStan\Rules\FunctionCallParametersCheck->check()
#1 .../Rules/Classes/InstantiationRule.php(78): PHPStan\Rules\Classes\InstantiationRule->checkClassName()
#2 .../Analyser/FileAnalyserCallback.php(134): PHPStan\Rules\Classes\InstantiationRule->processNode()
#3 .../Node/ClassStatementsGatherer.php(120): PHPStan\Analyser\FileAnalyserCallback->__invoke()
#4 .../Analyser/NodeScopeResolver.php(771): PHPStan\Node\ClassStatementsGatherer->__invoke()
...
Environment
PHPStan: 2.2.0
PHP: 8.x
Config: level: 10, bleedingEdge.neon included
The crash disappears when bleedingEdge.neon is removed.
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 10
paths:
- repro.php
Code snippet that reproduces the problem
https://phpstan.org/r/1b1462cc-ebcc-4d03-a897-2f3e33a7743b
Expected output
No crash
Did PHPStan help you today? Did it make you happy in any way?
Thanks for the update!
Bug report
PHPStan 2.2.0 crashes with an internal error in Rules/FunctionCallParametersCheck.php:155 when analysing a new self(...$properties) call in a child class whose constructor adds a promoted parameter on top of the parent's, and where $properties is built by iterating over the parent constructor's ReflectionMethod parameters.
The crash only occurs when bleedingEdge.neon is included. Without bleedingEdge, PHPStan reports a normal argument.type error and completes the analysis.
Stack trace (top frames)
Environment
PHPStan: 2.2.0
PHP: 8.x
Config: level: 10, bleedingEdge.neon included
The crash disappears when bleedingEdge.neon is removed.
Code snippet that reproduces the problem
https://phpstan.org/r/1b1462cc-ebcc-4d03-a897-2f3e33a7743b
Expected output
No crash
Did PHPStan help you today? Did it make you happy in any way?
Thanks for the update!