Skip to content

Commit e35b4fa

Browse files
phpstan-botclaude
andcommitted
Add test cases for method_exists with mixed and object types
Demonstrates that the false positive only occurs with template types (object&T), not with plain mixed or object. For mixed, ObjectWithoutClassType::isSuperTypeOf(MixedType) returns Maybe (mixed is not necessarily an object), preventing the false positive. For plain object, ObjectWithoutClassType::hasMethod() returns Maybe (via ObjectTypeTrait), also preventing it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ff42ae6 commit e35b4fa

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

tests/PHPStan/Rules/Comparison/data/bug-8217.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@ class HelloWorld
99
*
1010
* @param T $object
1111
*/
12-
public static function check($object): void
12+
public static function checkTemplate($object): void
1313
{
1414
if (is_object($object) && method_exists($object, 'method')) {
1515
echo 1;
1616
}
1717
}
18+
19+
public static function checkMixed(mixed $value): void
20+
{
21+
if (method_exists($value, 'method')) {
22+
echo 1;
23+
}
24+
}
25+
26+
public static function checkObject(object $object): void
27+
{
28+
if (method_exists($object, 'method')) {
29+
echo 1;
30+
}
31+
}
1832
}

0 commit comments

Comments
 (0)