Getting a fatal error when submitting comments with the current stable version using Akismet as the provider. This happens when you click save (with or without previewing):

Fatal error: Cannot use string offset as an array in /var/www/drupal7/sites/all/modules/antispam/antispam.module on line 1014

When previewing comments you get the following warning:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in antispam_comment_view() (line 1140 of /sites/all/modules/antispam/antispam.module).

CommentFileSizeAuthor
#10 antispam.module.patch2.12 KBegouleau
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kabojnk’s picture

Subscribing. I'm getting this, too. It only occurs when using the "Identify spambots by...".

Also, why do all of my unregistered commenters' names get replaced with "Anonymous" when this module is enabled?

This is the offending piece of code:

$debug_info['Content'] = $comment->mail[$comment->language][0]['value'];

And here's a PDO error for good measure if you comment out the previous line as well:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'c.comment' in 'where clause': SELECT s.content_id AS content_id FROM {antispam_spam_marks} s INNER JOIN {comment} c ON s.content_id = c.cid WHERE (s.content_type = :db_condition_placeholder_0) AND (s.hostname = :db_condition_placeholder_1) AND (s.mail = :db_condition_placeholder_2) AND (c.comment = :db_condition_placeholder_3) LIMIT 1 OFFSET 0; Array ( [:db_condition_placeholder_0] => comment [:db_condition_placeholder_1] => ::1 [:db_condition_placeholder_2] => viagra@viagra.com [:db_condition_placeholder_3] => Viagra ) in antispam_comment_presave() (line 1019 of /#############/sites/all/modules/contrib/antispam/antispam.module).
lsolesen’s picture

+1

lsolesen’s picture

Priority: Normal » Critical

This makes the module unusable, so setting the priority to critical.

libre fan’s picture

Title: Fatal errors » Fatal errors Undefined index, Argument #1 is not an array in antispam_comment_view, Cannot use string offset as an array

Recap: The following errors make Antispam unusable since I upgraded from D6 to D7. I tried uninstalling Antispam, and dropping the spam tables, reinstalling, but to no avail. Here's a sample of the errors I get:

Notice: Undefined index: comment in antispam_comment_view() (line 1140 of ...sites/all/modules/antispam/antispam.module).
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in antispam_comment_view() (line 1140 of ...sites/all/modules/antispam/antispam.module).

This is what I get as a logged in user if I want to add a comment and click on the "preview" button. Can't get past the error since there's no Ok button after this error.

If I set Preview as optional and click the save button instead I get this error:

Fatal error: Cannot use string offset as an array in…sites/all/modules/antispam/antispam.module on line 1014

I haven't found an alternative to Antispam, Captcha mayn't be enough.

Crossfeed’s picture

dirty workaround as mentioned above is to uncheck all 'Identify spambots by' options.
But even then the module 'forgets' the authors name and sets it to guest. Really unusuable in its current version

mgifford’s picture

I'm hoping this might fix this up however I just got a report about this problem and wasn't able to replicate it.

That's instead of line 1014:

    if (!empty($comment->language) && is_array($comment->mail[$comment->language][0]['value'])) {
      $debug_info['Content'] = $comment->mail[$comment->language][0]['value'];
    }
    else {
      $debug_info['Content'] = '';
    }

I am finding that in general antispam has been working for me.

mgifford’s picture

Ultimately I had to mostly comment this out. I'm really not sure why the object that's being returned is producing an error. I think it only affects forum comments, but still it's a problem. This was the best documentation I could find about this general php issue:

http://informationideas.com/news/2006/06/14/fatal-error-cannot-use-strin...

I temporarily fixed this bug (well by commenting out the section) in this patch here:
#1349574: Coder Cleanup, Link Fix & Fatal Error Fix

danithaca’s picture

I have the same problem too. Subscribe.

jamescl’s picture

Was also occurring with comments on node, patch in #7 solves for me.

egouleau’s picture

FileSize
2.12 KB

well, in fact there are 2 errors in the function antispam_comment_presave($comment)...

Find out that the query conditions where bad when checking the antispam options

Identify spambots by : Content that has already been identified as spam.

but also the debug_info['Content'] do not get the right value...

  • First, the debug_info['content'] value :
if ($antispambot_rules['body'] && !empty($comment->comment_body)) {
    $query->condition('c.comment', render($comment->comment_body[$comment->language][0]['value']));
    $debug_info['Content'] = $comment->mail[$comment->language][0]['value'];
    $num_condition++;
  }

we don't want $comment->mail but $comment->body :)
that's solve the

Fatal error: Cannot use string offset as an array in…sites/all/modules/antispam/antispam.module on line 1014


  • Then the most important, the query conditions : we got on line 993 in the antispam.module
$query = db_select('antispam_spam_marks', 's');
  $query->fields('s', array('content_id'));
  if ($antispambot_rules['body']) {
    $query->join('comment', 'c', 's.content_id = c.cid');
  }

and on line 1012

if ($antispambot_rules['body'] && !empty($comment->comment_body)) {
    $query->condition('c.comment', render($comment->comment_body[$comment->language][0]['value']));
    $debug_info['Content'] = $comment->mail[$comment->language][0]['value'];
    $num_condition++;
  }

but when looking to the table comment in the db there is no "comment" field ...
there's missing another query join to get this function to work.

I changed the code like this on line 993 :

$query = db_select('antispam_spam_marks', 's');
  $query->fields('s', array('content_id'));
  if ($antispambot_rules['body']) {
    $query->join('comment', 'c', 's.content_id = c.cid');
    $query->join('field_data_comment_body', 'cb', 'c.cid = cb.entity_id');
  }

and on line 1012 :

if ($antispambot_rules['body'] && !empty($comment->comment_body)) { 
    $query->condition('cb.comment_body_value', render($comment->comment_body[$comment->language][0]['value'])); 
    $debug_info['Content'] = $comment->comment_body[$comment->language][0]['value'];
    $num_condition++;
  }

solve the problem for me :)
Hope it helps

monbro’s picture

@egouleau your solution worked for me, thanks!

When i change or insert a new user, there was also a fatal error.
Solved (and working) by changing the line:

$result = db_query("SELECT * FROM {antispam_moderator_email_for} WHERE uid=:uid", array(':uid' => $account->uid));

to

$result = db_query("SELECT * FROM {antispam_moderator} WHERE uid=:uid", array(':uid' => $account->uid));
wxman’s picture

I just found I had this going on too. The patch worked for me as well.

tim.plunkett’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

There was a similar fix over here: #1483796: AntiSpam fatal error when posting comments.

That has been committed. Please test and see if this issue was a duplicate.

lklimek’s picture

Priority: Normal » Minor

I got the "Fatal error: Cannot use string offset as an array in /var/www/drupal7/sites/all/modules/antispam/antispam.module on line 1014" error recently, but installing latest -dev version fixed my problem.

DamienMcKenna’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (duplicate)
manuscle’s picture

Patch worked for me too :)