Skip to content

Cannot apply #[\Attribute] to abstract class on PHP 8.5 #19694

@nicolas-grekas

Description

@nicolas-grekas

Description

This worked on 8.4 and before, and doesn't anymore on 8.5:

<?php


#[\Attribute(\Attribute::TARGET_CLASS)]
abstract class Base
{
}

#[\Attribute(\Attribute::TARGET_CLASS)]
class Child extends Base
{
}

#[Child]
class A
{
}
$r = new \ReflectionClass('A');

var_dump($r->getAttributes('Base', ReflectionAttribute::IS_INSTANCEOF));

Resulted in this output:

Fatal error: Cannot apply #[\Attribute] to abstract class Base in /in/isSn6 on line 5

But I expected this output instead:

array(1) {
  [0]=>
  object(ReflectionAttribute)#2 (1) {
    ["name"]=>
    string(5) "Child"
  }
}

PHP Version

PHP 8.5

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions