Closed
Description
Symfony version(s) affected
6.1+
Description
Promoted properties may have a doc comment, so the following code (see https://3v4l.org/csbKl):
<?php
class A {
public function __construct(
/**
* @var class-string
*/
public string $promoted,
) {
// empty
}
}
$class = new ReflectionClass(A::class);
$property = $class->getProperty('promoted');
var_dump($property->getDocComment());
will dump:
string(44) "/**
* @var class-string
*/"
Phpstan itself also reads the type from the promoted property correctly (see https://phpstan.org/r/6de7935b-1d48-49bc-afd2-5748ec5523ac):
But the PhpStanExtractor
ignores the property comment and always tried to use __construct
comment:
symfony/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php
Lines 239 to 243 in 37f04cf
How to reproduce
// First, run "composer require symfony/property-info"
// Then, execute this file:
<?php
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
require_once __DIR__.'/vendor/autoload.php';
class A {
public function __construct(
/**
* @var class-string
*/
public string $promoted,
) {
// empty
}
}
$extractor = new PhpStanExtractor();
$types = $extractor->getTypes(A::class, 'promoted');
var_dump($types); // NULL