Skip to content

Commit e86742d

Browse files
committed
get_class() returns false for mixed argument types
This reverts commit 921f48e.
1 parent f76875a commit e86742d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Type/Php/GetClassDynamicReturnTypeExtension.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,19 @@ static function (Type $type, callable $traverse): Type {
4949
}
5050

5151
if ($type instanceof TemplateType && !$type instanceof TypeWithClassName) {
52-
return new GenericClassStringType($type);
52+
if ($type instanceof ObjectWithoutClassType) {
53+
return new GenericClassStringType($type);
54+
}
55+
56+
return new UnionType([
57+
new GenericClassStringType($type),
58+
new ConstantBooleanType(false),
59+
]);
5360
} elseif ($type instanceof MixedType) {
54-
return new ClassStringType();
61+
return new UnionType([
62+
new ClassStringType(),
63+
new ConstantBooleanType(false),
64+
]);
5565
} elseif ($type instanceof StaticType) {
5666
return new GenericClassStringType($type->getStaticObjectType());
5767
} elseif ($type instanceof TypeWithClassName) {

tests/PHPStan/Analyser/data/generics.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ function arrayOfGenericClassStrings(array $a): void
12991299
function getClassOnTemplateType($a, $b, $c, $d, $object, $mixed, $tObject)
13001300
{
13011301
assertType(
1302-
'class-string<T (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>',
1302+
'class-string<T (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>|false',
13031303
get_class($a)
13041304
);
13051305
assertType(
@@ -1324,7 +1324,7 @@ function getClassOnTemplateType($a, $b, $c, $d, $object, $mixed, $tObject)
13241324
);
13251325

13261326
assertType('class-string', get_class($object));
1327-
assertType('class-string', get_class($mixed));
1327+
assertType('class-string|false', get_class($mixed));
13281328
assertType('class-string<W of object (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>', get_class($tObject));
13291329
}
13301330

0 commit comments

Comments
 (0)