Notice: Undefined property: stdClass::$hostname in comment_notify_comment_insert() (line 259 of /home/xx/public_html/dev/sites/all/modules/comment_notify/comment_notify.module).

getting that error upon submitting a comment in my forum.

#17 isset.patch1.42 KBRobLoach


I have no idea how this could be happening - there is clearly a $comment->hostname = ip_address() before module_invoke_all('comment_insert', $comment) is run in comment_save().

There was also a report of this at

@duckx - can you clarify what your configuration is?

on line: 259 $notify_hash = drupal_get_token($comment->hostname . $comment->cid);

i had to remove the hostname reference to make it work. i updated the token module to the latest too and still no good. where is this hostname reference declared?

The hostname should be on all comments. What settings do you have? Something you configured is different from default and causing this issue (we can work around that, but I'd like to know :) ).

its a Drupal 7.0 install. would tat be it? if you can point to me where the hostname is being declared or registered i can look at my instance and see if it resides there too.

Hi, I updated my drupal install from 7.0 to 7.4 and the notice: Undefined property: stdClass::$hostname has gone.

There is still one notice remaining - if I post a comment as an unregistered user and do not provide email:
Notice: Trying to get property of non-object ve funkci _comment_notify_mailalert() (řádek: 418 v souboru /data/web/virtuals/1198/virtual/www/sites/all/modules/comment_notify/comment_notify.module).

If i comment as a registered user, it is ok. In the code there is:

if (empty($comment->mail)) {
    $comment_account = user_load_by_name($comment->name);
    $comment_mail = $comment_account->mail;
  else {
    $comment_mail = $comment->mail;

Seems comment_account->mail is defined only if user is registered. If i understand the logic here well, the purpose is to get an email address for a later test, whether the autor of the comment isnt the same as the mail from the notifications list, so setting it to '' should do.

I changed the code to the below and it seems to work:

  if (empty($comment->mail)) {
    $comment_account = user_load_by_name($comment->name);
    $comment_mail = isset($comment_account->mail) ? $comment_account->mail : '';
  else {
    $comment_mail = $comment->mail;

Btw, I changed my username from vlx to Jiri Volf

Title:Notice: Undefined property: stdClass::$hostname in comment_notify_comment_insert() (line 259Notice: Trying to get property of non-object line 418 comment_notify.module

Updating title, thanks for letting me know.

Status:Active» Postponed (maintainer needs more info)

It seems like this might be a core issue. Can anyone else confirm that updating to Drupal 7.4 makes the issue go away?

Same issue. Drupal is upgraded.

@mefisto75, can you start over with a brand new installation of Drupal. Install comment notify, and see if the problem is present? If not, can you make changes related to comments to make it the same as the site where you have the problem?

This bug seems to affect a minority of users and without clear steps to reproduce it will be hard to fix it.

I will do with the next site) This one is too late to change anything. Will report back. It may have something to do with comment publish permissions (skip approval or not). Not sure though.

@mefisto75, I'm not asking you to change anything, I'm asking you to install a test site.

I'm tempted to mark this "cannot reproduce" since it's been almost a month since the last report. Is anyone still having this problem.

I should say "still having this problem with an up to date comment_notify and up to date core."

Hi, I have just made a fresh install of D7.8, put comment notify 7.x-1.0-rc1 and token 7.x-1.0-beta5 modules, enabled anon users subscribing to notifications and posting comments, enabled users to put in their contact details and created a test article and posted an anonymous test comment and got the same message as i wrote at #6, except that instead of 418 the code has moved to line 454 in this version.

Notice: Trying to get property of non-object in _comment_notify_mailalert() (line 454 of /data/www/
Notice: Trying to get property of non-object in _comment_notify_mailalert() (line 454 of /data/www/

When changed comment_notify.module, line 454 from:
$comment_mail = $comment_account->mail;
$comment_mail = isset($comment_account->mail) ? $comment_account->mail : '';
the error went away.

I'm still new to drupal and don't know how to make patches and haven't set up any development tools, so this is my best I can contribute now. I see you have just released rc1... sorry that I haven't tested it earlier... I put it even on my to-do list but didn't get to it until now...

However, this notice is a bit different from the one originally reported (on line 259) - that error has gone with the upgrade of drupal. This one on line 418(earlier dev)/454(rc1) is probably unrelated to the original one.

Version:7.x-1.x-dev» 7.x-1.0-rc1
Status:Postponed (maintainer needs more info)» Active

Ran into this on rc1 as well.

Status:Active» Needs review
new1.42 KB

Having troubles reproducing the Notices, but I did find them in my logs. Having some isset checks in there will help. The attached patch adds isset() checks to the Notices I found in the log.

Version:7.x-1.0-rc1» 7.x-1.x-dev


Thanks, Rob.

I think it might require more than this. If we don't get a thread or don't get a mail we probably need to bail out instead of trying to mail them. I'll try to review and think more soon.

Status:Needs review» Fixed

Thanks, Rob!

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.