phpstan-strict-rules
phpstan-strict-rules copied to clipboard
FR: report overriding outer scope var in `catch` statement
private static function printExceptionMessage(\Throwable $e) : string{
$errstr = preg_replace('/\s+/', ' ', trim($e->getMessage()));
$errno = $e->getCode();
try{
$errno = ErrorTypeToStringMap::get($errno);
}catch(\InvalidArgumentException $e){
//pass
}
$errfile = Filesystem::cleanPath($e->getFile());
$errline = $e->getLine();
return get_class($e) . ": \"$errstr\" ($errno) in \"$errfile\" at line $errline";
}
This code is sampled from a bigger project in which I discovered a bizarre bug today: this function always reports that the passed exception came from ErrorTypeToStringMap
if the exception code was non-zero.
This happened because the catch block overrides the variable $e
, and the change persists outside of the catch.