php – Fix error Gravatar alt

add_filter( 'get_avatar' , 'alt_name_avatar');
function alt_name_avatar( $avatar ) {
    $alt = get_comment_author();
    $avatar = str_replace('alt=''','alt='Avatar for '.$alt.'' title='Avatar for '.$alt.''',$avatar);
    return $avatar;
}

This code works but throws an error.

PHP Notice:  Trying to get property 'user_id' of non-object in .../wp-includes/comment-template.php on line 28
PHP Notice:  Trying to get property 'comment_ID' of non-object in .../wp-includes/comment-template.php on line 48

How to fix.

P.S.
i use on all pages recent comments with Gravatar in the sidebar

Sorry for my English.