-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Closed
Copy link
Labels
Milestone
Description
Bug report
When using ReflectionMethod methods invoke() or invokeArgs(), PHPStan does not consider that exceptions can be thrown, resulting in the "dead catch" error. This happens with both instance methods and static methods (first parameter set to null).
This does apply for ReflectionFunction which correctly assumes that any exception can be thrown.
Tested on version 1.10.14 and with the online tool with bleeding edge option.
Code snippet that reproduces the problem
<?php declare(strict_types = 1);
class FooException extends Exception {}
function bar(\ReflectionMethod $r): void {
try {
$r->invoke(new C);
}
catch (FooException $e) {
print "CAUGHT FOO!\n";
}
}
class C {
/** @return never */
public function test() {
throw new FooException("");
}
}
bar(new ReflectionMethod("C", "test"));https://phpstan.org/r/9ec6f070-c552-40fa-bbdb-b0b9888906c0
Expected output
No errors.
Reactions are currently unavailable