Skip to content

Using anonymous class breaks discovering symbols (Fatal error) #3663

@davidbrnovjak

Description

@davidbrnovjak

Bug report

Using anonymous class definition inside another class leads to Fatal error during symbol discovery

Internal error: Internal error: Class 'Granularity' not found in file /var/www/html/sts3/app/modules/Statistics/Granularity.php

Removing the anonymous class definition resolves the error.

Code snippet that reproduces the problem

Unable to reproduce in playground.

Class snippet
<?php

declare(strict_types=1);

class Granularity
{
    protected static function provideInstances(): array
    {
        $myclass = new class() extends Granularity { };

        return [];
    }
}
PHPStan debug trace
PHP Fatal error:  Uncaught Error: Class 'Granularity' not found in phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129) : eval()'d code:1
Stack trace:
#0 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): eval()
#1 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/ReflectionProvider/ClassBlacklistReflectionProvider.php(97): PHPStan\Reflection\Runtime\RuntimeReflectionProvider->getAnonymousClassReflection(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope))
#2 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/ReflectionProvider/ChainReflectionProvider.php(55): PHPStan\Reflection\ReflectionProvider\ClassBlacklistReflectionProvider->getAnonymousClassReflection(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope))
#3 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/ReflectionProvider/MemoizingRef in phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129) : eval()'d code on line 1
Fatal error: Uncaught Error: Class 'Granularity' not found in phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129) : eval()'d code:1
Stack trace:
#0 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): eval()
#1 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/ReflectionProvider/ClassBlacklistReflectionProvider.php(97): PHPStan\Reflection\Runtime\RuntimeReflectionProvider->getAnonymousClassReflection(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope))
#2 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/ReflectionProvider/ChainReflectionProvider.php(55): PHPStan\Reflection\ReflectionProvider\ClassBlacklistReflectionProvider->getAnonymousClassReflection(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope))
#3 phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/ReflectionProvider/MemoizingRef in phar:///var/www/html/sts3/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129) : eval()'d code on line 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions