Global $post not working in OOP function WordPress

First function works fine, because comment form is displayed just after post. So it’s the same request and global variable post still contains current post.

On the other hand, comment_post is run in another request – a POST request containing the newly added comment. So there is no global post object, because no post should be displayed.

That’s why this function takes comment_ID as first param. This comment is already in DB, so you can select it and then get the post it’s assigned to.

If you want to use post in comment_post, you should do it based on its params:

add_action( 'comment_post', 'show_message_function', 10, 2 );
function show_message_function( $comment_ID, $comment_approved ) {
    $comment = get_comment( $comment_ID );
     $post_ID = $comment->comment_post_ID;
     ...
}

So… It has nothing to do with OOP. It’s about when and where is given function called and what global variables are available then.