Bug report
PHPStan seems to incorrectly assume that string conversions cannot throw exceptions. While this used to be the case (although there were obscure workarounds), this is now officially supported: https://wiki.php.net/rfc/tostring_exceptions.
Consider the program below:
try {
(string) $myVariable;
} catch (Exception) {
// Reported as dead catch, even though the `__toString()` method
// in `$myVariable` might throw an exception.
}
See also: https://3v4l.org/Ze7r6#v8.4.14
Code snippet that reproduces the problem
https://phpstan.org/r/f0ac2617-d1d7-4537-bcfe-f5127dfd002c
Expected output
No issues are reported.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan has been incredibly useful for us in detecting errors and issues early! Thank you for the great work.
Bug report
PHPStan seems to incorrectly assume that string conversions cannot throw exceptions. While this used to be the case (although there were obscure workarounds), this is now officially supported: https://wiki.php.net/rfc/tostring_exceptions.
Consider the program below:
See also: https://3v4l.org/Ze7r6#v8.4.14
Code snippet that reproduces the problem
https://phpstan.org/r/f0ac2617-d1d7-4537-bcfe-f5127dfd002c
Expected output
No issues are reported.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan has been incredibly useful for us in detecting errors and issues early! Thank you for the great work.