Skip to content

ReflectionProperty does not return the PHPDoc of a property if it contains an attribute with a Closure #20895

Description

@zavarock

Description

The following code:

<?php
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Hello {
    public function __construct(
        public ?Closure $world = null,
    ) {
    }
}

class Foo {
    /**
     * @var string
     */
    #[Hello(static function() {
        return null;
    })]
    public $bar;
}

$reflectionProperty = new ReflectionProperty(Foo::class, 'bar');

var_dump($reflectionProperty->getDocComment());

Resulted in this output:

bool(false)

But I expected this output instead:

string(30) "/** * @var string */"

PHP Version

PHP 8.5.0

Operating System

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions