Notice: Trying to get property of non-object in function MY_MODULE_form_comment_form_alter() I have an error Notice: Trying to get property of non-object in function MY_MODULE_form_comment_form_alter()
This error is related to the line if ($node->nid == $comment->nid)  and I think to $comment->nid

I suppose that it is needed to describe $comment->nid  as an object like for $node->nid an expression $node = menu_get_object() was used. I was searching for this similar program code and with no success.
I have to use $form['#attributes']['class'][] = 'new-comment-form';  and that is why hook_form_alter is used.
Maybe there is another solution to this problem?

The code is:

function MY_MODULE_form_comment_form_alter(&amp;$form, &amp;$form_state, &amp;$comment_count, &amp;$comment) {
    if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
      $node = node_load(arg(1));
      if (isset($node-&gt;uid, $GLOBALS['user']-&gt;uid) &amp;&amp; $GLOBALS['user']-&gt;uid == $node-&gt;uid &amp;&amp; $GLOBALS['user']-&gt;uid &gt; 0) {
        $form['#attached']['css'] = array(
          drupal_get_path('module', 'MY_MODULE') . '/MY_MODULE.css.');
        }
    }

    $node = menu_get_object();


        if ($form['#node']-&gt;comment_count == 0 ){
        // hide a field
            drupal_add_css(drupal_get_path('module', 'MY_MODULE') . '/MY_MODULE2.css.'); 
        }

        if ($node-&gt;nid == $comment-&gt;nid) {
            $form['#attributes']['class'][] = 'new-comment-form';
        }

}
You have the wrong function signature. It is supposed to be:

hook_form_FORM_ID_alter(&amp;$form, &amp;$form_state, $form_id)


In your function, $comment_count is set as the form_id, and $comment will always be null.

Set it to the signature above, then use $form['nid'] and $form['cid']. To get the comment count on the node, inspect at $form['#node']->comment_count

Here is a replacement code for what you are trying to do:

function MY_MODULE_form_comment_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form['#node']-&gt;comment_count){
    // node has comments
    $form['#attached']['css'] = array(
        drupal_get_path('module', 'MY_MODULE') . '/MY_MODULE.css.', 'file');
  }
  else {
    // no comments on the node
    $form['#attached']['css'] = array(
      drupal_get_path('module', 'MY_MODULE') . '/MY_MODULE2.css.', 'file');
    $form['#attributes']['class'][] = 'new-comment-form';
  }
}