Skip to content

Unable to use ->getAttributes(Whatever::class, ReflectionAttribute::IS_INSTANCEOF) on certain classes #9618

@janedbal

Description

@janedbal

Bug report

I'm implementing custom rule that does

InClassNode->getClassReflection()->getNativeReflection()->getMethods()[each]->getAttributes(Whatever::class, ReflectionAttribute::IS_INSTANCEOF)

which fails when analysing file similar to this:

class MyRuntimeException extends \RuntimeException {}

getting error:

 ------ ---------------------------------------------------------------------------------------- 
  Line   MyRuntimeException.php                                                                
 ------ ---------------------------------------------------------------------------------------- 
  5      Reflection error: JetBrains\PhpStorm\Internal\PhpStormStubsElementAvailable not found.  
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                     
         ✏️  tests/src/ShipMonk/Exception/TestRuntimeException.php:5                             
 ------ ----------------------------------------------------------------------------------------

It looks like it is coming from vendor/phpstan/phpstan/phpstan.phar/vendor/jetbrains/phpstorm-stubs/Core/Core_c.stub:312 which contains

class Exception implements Throwable
{
    #[PhpStormStubsElementAvailable("8.1")]
    private function __clone(): void {}
}

when better-reflection tries to reflect attribute class within ReflectionAttributeHelper::filterAttributesByInstance

Code snippet that reproduces the problem

No response

Expected output

No error

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions