Skip to content

get_debug_type produces wrong type for anonymous classes with parent #11562

@mvorisek

Description

@mvorisek

Bug report

The get_debug_type() produces currently a wrong constant string type.

/cc @patrickkusebauch, related with phpstan/phpstan-src#2910

phpstan-src test:

diff --git a/tests/PHPStan/Analyser/nsrt/get-debug-type.php b/tests/PHPStan/Analyser/nsrt/get-debug-type.php
index 975ea62..8ec1c48 100644
--- a/tests/PHPStan/Analyser/nsrt/get-debug-type.php
+++ b/tests/PHPStan/Analyser/nsrt/get-debug-type.php
@@ -18,6 +18,7 @@ function doFoo(bool $b, int $i, float $f, $d, $r, string $s, array $a, $intOrStr
 	$o = new \stdClass();
 	$A = new A();
 	$anonymous = new class {};
+	$anonymousWithParent = new class extends \stdClass {};
 
 	assertType("'bool'", get_debug_type($b));
 	assertType("'bool'", get_debug_type(true));
@@ -35,6 +36,7 @@ function doFoo(bool $b, int $i, float $f, $d, $r, string $s, array $a, $intOrStr
 	assertType("'int'|'string'", get_debug_type($intOrString));
 	assertType("'array'|'GetDebugType\\\\A'", get_debug_type($arrayOrObject));
 	assertType("'class@anonymous'", get_debug_type($anonymous));
+	assertType("'stdClass@anonymous'", get_debug_type($anonymousWithParent));
 }
 
 /**

Code snippet that reproduces the problem

https://phpstan.org/r/f8fea2c3-61e7-416a-844f-24adf0e53377

Expected output

Dumped type: 'stdClass@anonymous'

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