I'm having quite a similar problem as in http://drupal.org/node/71008.

Fatal error: Cannot use object of type stdClass as array in /usr/home/demadridalcamino/www/pruebas/modules/contrib/subscriptions/subscriptions.module on line 540

I'm using v 1.38.2.3.2.12

It's independant of whether I use cron or not. I'm not using any tests. This error occurs when clicking on some posts. Only some, but not all. It happens in about 75% of all posts. I haven't been able to discover any similarity or difference in posts where this happens, and where it doesn't. It's the same for anonymous users and for any other kind of registered user, including admin user.

Comments

atreides-1’s picture

I just kept on checking. The problem happens only in topics that already have got some comments. Posts that I can see (without problems) are only the ones that haven't been commented. Giving all permissions to subscriptions and comment modules doesn't help.

dziemecki’s picture

I'm not sure I have the sequence required to dupe this error. It sounds like you are saying this:

1. Turn on the 'Use cron for notifications' and 'Test held posts prior to sending' options.
2. Make a comment to a thread that has already had comments.
3. Run /cron.php.
4. Observe the errors.

Is that right? If so, it worked without error for me. Are you using the forum module? Let's try to be as specific as possible because, as soon as I can dupe it, I can fix it.

sol77’s picture

I am getting the same error when trying to view posts with comments. I am using the same version of the module.
I also get that error when going from a feed to posts that have comments, and when posting a comment to a post that has no comments.
What I have done is import the posts from a phpBB forum and then afterwards installed Subscriptions.
I have shut down every available module except for comment, forum, taxonomy and subscriptions of course and I still get the error.

dziemecki’s picture

sol77 - please see my post above concerning the sequence of steps required to duplicate the error. I have not yet been able to, so I need to know the exact steps you use to generate the failure.

sol77’s picture

I tried doing what you said but I can't even view posts that have comments, or make a new comment to a new post.

sol77’s picture

Ok, first I install Drupal and use the database 4.0 mysql setup.
Then I install TAC_lite, bbcode, phpBB2drupal, privatemsg, forums, comment_upload, poll, upload, upload_image and subscriptions.
Next step is using phpBB2drupal which goes fine except for some warning on importing polls.

Now when I click on a post nomatter from frontpage, if I have promoted anything, a feed or the forums I get the error posted above, and I can not make new posts.
The first thing I did was to enter the forums and click on a post that had comments.

I don't have cronjobs installed btw.

Is this sufficient information?

sol77’s picture

I forgot to include the module profile in my post above..

I tried the same thing with the database structure for mysql 4.1 and better. Same result.
The version of mysql on my server seems to be 5.0.22.

Any ideas?

dziemecki’s picture

My comments above weren't suggested steps to take - they were an example of an attempt to show what a bug report needs to look like for me to address it. I have to know exactly what you do to dupe the error. My current suggestion os for you to diable every single contributed module, then add them back one at a time to confirm which module or combination of modules generate the error. Then back out the other module one a time to confirm which ones are responsible, and minimize the variables. FInally, write up a dupe script that list what modules are active, and what steps are taken to display the error.

It might also be very helpful if you would turn on error display:

php_value display_errors 1

This might generate a very specific error message.

sol77’s picture

I'll give it a shot. English is only my third language but I think I understood you correctly.

I'm supposed to write "php_value display_errors 1" in the .htaccess file that installed with Drupal?

dziemecki’s picture

Yup.

atreides-1’s picture

StatusFileSize
new19.64 KB

The curious thing is that I'm not doing anything special as a procedure to have this error. What I tried to explain, mostly in comparison to other thread, is that whatever options I use (or not use), the result is the same.

I turned on errors on screen, but still, the only thing I get is the same error message:
Fatal error: Cannot use object of type stdClass as array in /usr/home/demadridalcamino/www/modules/contrib/subscriptions/subscriptions.module on line 540

Instead, in logs there are some errors registered. I've got them in Spanish, but I guess in English the exact phrase is "Page not found". I've attached a screenshot. It's in Spanish, but I guess / hope that it is understandeable, at least to see what errors appear.

I just installed the module, and it started failing. I read a similar thread, where it depended on the subscription settings, so I tried it, but with no positive results.

Maybe it's related to some other module installed.

atreides-1’s picture

Sorry ..., I just mistook the error. Please, don't pay any attention to the reference and screenshot that I sent. It must be searchers, that are searching for wrong pages. I don't think it is related at all to this problem.

sol77’s picture

I added the text to .htaccess but didn't get any more information when the error message appeared, or maybe I need to look for it somewhere else?
Did I need to put in one of the blocks? I simply put it by it self.

However, here is my dupe script.
This is after having created the first account and modifying the htaccess file according to above.

1. turn off all modules and add so that only comment, story, subscriptions and taxonomy are active.
2. Create a story.
3. Add comment with nothing in the subject block.

Then the error appears after hitting the preview button.

atreides-1’s picture

I made some tests with modules:

As sol77, I left only the comments, taxonomy, story and subscription modules. Still I couldn't access stories with comments.

I disabled comments modules, and as I expected, it worked perfectly.

I enabled all modules I want to have (don't know how many, didn't even count them). But I deactivated comments module, and everything worked perfect.

So, somehow it looks like it's something related with comments module.

I also added php_value display_errors 1, to different parts in the .htaccess, for Apache 1, 2 and both in case of PHP5. When error occurs, it is exactly the same message. Nothing more.

Assigning all permissions to both comments and subscriptions modules doesn't add anything either. Same about clean URLs and cache, and as well when I change comments behaviour: no change.

If I change, in admin/comment/configure, the default display mode to any that is collapsed, I can access and see perfectly all stories, also with comments. But in this case, the problem occurs again, when I try to read any comment.

Hope it helps a bit.

Cláudio’s picture

Hi,
Just trying to put a little more information . . .
Reproduced the same here, in a test site with no content. Fresh install.
I have Apache 2, php 5.0.5, MySQL 5.0.15
Here are the steps to reproduce de problem. I tried to be as detailed as possible, so you can check if I missed some step:

  1. Installed drupal 4.7.2: copied files to a test directory in my web server, created the database.
  2. Created Admin account
  3. Installed subscriptions module: downloaded the module from the module list for drupal 4.7, expanded the gz in modules/contrib, enabled module in the admin/modules page. The database tables are automatically created. The version reported in the first line of the module is 1.38.2.3.2.12
  4. Configured in the admin/settings/subscriptions: enabled Notify poster of own posts option
  5. Configured subscriptions for user: enabled for page in user/1/subscriptions/type (the complete path to get there was Administer -> user -> edit -> my subscriptions -> my content types)
  6. Created a new page. Enabled subscribe for that page. An email was generated and sent after the page was created.
  7. Created a comment for that page. When I hit the preview button, the error shows up in a blank screen:
    Fatal error: Cannot use object of type stdClass as array in
    If I comment the line $nid = $comment['nid']; in the line 540 of the module, the error disappear - but it doesn send an email either.

I hope that helps you reproduce the problem.

dziemecki’s picture

This appears to be an issue with differences between PHP 4 (my dev environment) and 5 (your prod environment). There are supposed to be ways to address this, so I'll investigate how I can get the same functionality with object notation.

dziemecki’s picture

StatusFileSize
new46.8 KB

I've modified the comment hook to use object notation. It works for me, but it always has. Maybe one of you guys running PHP 5 can give it a whirl.

Cláudio’s picture

StatusFileSize
new72.79 KB

Dan:

You are right, the original module works with php 4. But the modified version you just posted, no matter the php version, gaves a similar error, shown in the attached screens. 2 files, each with the proper php version in the name. The environment is the same, I activated first php 5, and then php 4. (So: the upper part is with PHP5, the lower with PHP4).
I have xampp (www.apachefriends.org) in my Linux box at home, and it is easy to switch php versions.
I did the tests recreating the database tables between each activation of drupal.
The error showed up when I tried to post a comment in a subscribed page. The comment is posted, but no email was sent.
Are you using drupal 4.7.2?
Does the module depend on a special php option?

dziemecki’s picture

Yes, I'm using the latest Drupal (plus a couple older ones). As for PHP option dependencies, I am not aware of any.

I think the errors you posted are definitely different from the ones I was responding to. For one thing, neither of them mention this module. Does the module work, despite the displayed error messaged? I know that Drupal display quite a few error messages when I turn error_display on that have no real impact. Is this the only module that generates errors?

Cláudio’s picture

Different? I don't think so. The message is exactly the same reported by atreides.
I'm not using any other modules; it's the default install, with nothing else other than subscriptions module.
And it seems to me that Error Display has nothing to do with the messages: I put php_value display_errors 1 active only for php5 (inside IfModule mod_php5.c of .htaccess), and the errors appears, no matter if I'm using php4 or php5.

If there is something more that I may do to help, please let me know.

dziemecki’s picture

Yes: Different. I am responding to the error at the very top of this thread - the reason for this issue:

Fatal error: Cannot use object of type stdClass as array in /usr/home/demadridalcamino/www/pruebas/modules/contrib/subscriptions/subscriptions.module on line 540

You mentioned it in one of your own posts, as well.

That error inescapably points to something going wrong in my code. And it points to the exact line. I'm pretty sure I fixed that with the file I attached.

Your other error is much harder to pin down, and it doesn't mention this module in any way. Are you certain that the error has something to do with Subscriptions? If you deactivate\delete subscriptions, does it go away?

Cláudio’s picture

I sent you an email using your contact form with further information.

atreides-1’s picture

Dan,

I tried the file you posted, and it works everything perfectly. Problem solved!

Thank you very much for your dedication, and also patience for all these things!

atreides-1’s picture

Sorry, Dan ...

I checked more closely the behavior with the file you posted, and I noticed that it gives the same errors that Cláudio says. The initial problem is in fact solved, which is not being able to see any comments when subscription module is enabled, but it gives now those same errors and there isn't either any email sent as for notification for new content.

It is true, anyway, and as you said, that in those errors there isn't any mention to subscriptions module.

I must admit all these is over my skills, but if you need anything to be tested, just say so, and I will try it.

Thanks once more

dziemecki’s picture

The next step will probably take a while, then. It's looking like a problem with PHP5 not being fully backwards compatible with PHP4, so I'm going to have to build out a PHP5 test environment (to go along with my current one) to see if I can narrow in in the root of the error. Without any hints as to what about Subscriptions is causing the problem, I have no idea how long it will take to correct this this.

sol77’s picture

Thanks for working on it.

RobRoy’s picture

Status: Active » Needs review
StatusFileSize
new1.7 KB

It is simply an issue of Drupal 4.7 passing $comment as an object to hook_comment(). So all calls must be in the form of $comment->nid or whatever. Here is a patch, let me know if that fixes it.

dziemecki’s picture

RobRoy,

Thanks for the patch but I actually posted that fix up in comment #16. Unfortunately, people are still getting the bug displayed in comment #17.

RobRoy’s picture

Duh, thought I would wizz in without reading all the comments and fix the issue! Okay, I'll dig deeper with a debug_backtrace() and see if I can reproduce the other error.

RobRoy’s picture

I installed PHP5, but can't reproduce the second error (in the PNG). Do you have instructions for reproducing that implode() error?

dziemecki’s picture

Nothing you don't see here, unfortunately.

RobRoy’s picture

Have you been able to reproduce it Dan?

zostay’s picture

After applying the patch you supplied, I'm getting three different errors for each comment. I'm going to try and track them down because the Subscription module is ideal for part of our new extranet. However, in the meantime, here's the errors I'm seeing:

First, I get this:

Invalid argument supplied for foreach() in 
/home/BOOMER/andrew/workspace32/boomer.com-drupal/modules/node.module on line 359.

Followed by:

implode() [function.implode]: Bad arguments. in 
/home/BOOMER/andrew/workspace32/boomer.com-drupal/modules/node.module on line 363.

And finished up with:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
 right syntax to use near '' at line 1 query: SELECT DISTINCT(n.nid), n.vid, n.type, n.status, n.created, n.changed, 
n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, 
r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions
 r ON r.vid = n.vid WHERE in /home/BOOMER/andrew/workspace32/boomer.com-drupal/includes/database.mysql.inc on
 line 120.

The errors are always just these three. Prior to the patch I see the exact error reported in the initial post. I'm running Apache 2, PHP 5, and Drupal 4.7.2. Here's the full list of modules I currently have installed: basicevent, comment, content, date, event, event_views, forum, help, menu, nodereference, number, optionwidgets, page, profile, story, taxonomy, text, userreference, views, views_rss, views_theme_wizard, views_ui, and weburl.

dziemecki’s picture

Have you been able to reproduce it Dan?

No, I'm still building a PHP5 environment. Might be a little while.

The errors are always just these three. Prior to the patch I see the exact error reported in the initial post. I'm running Apache 2, PHP 5, and Drupal 4.7.2.

My "patch" looks to consistently work well with PHP4 (which doesn't need it) and consistently fail with 4.5. I'm genning up a PHP5 dev environment to see if I can dupe it. This is unquestionably my top priority for this module.

zostay’s picture

Dan,

I just inserted this:

watchdog('debug', print_r($op, true).' '.print_r($comment, true));

before line 540 and found that the $comment is an array unless $op == "view".

Thus, all that's needed to remove the error is move:

$nid = $comment['nid'];

inside the if-statement. The $nid isn't used anywhere outside, so that's a better place for it to be scoped anyway.

dziemecki’s picture

Title: Fatal error: Cannot use object of type stdClass as array » Fatal error: Cannot use object of type stdClass as array (PHP5 Only)
Assigned: Unassigned » dziemecki
StatusFileSize
new46.8 KB

Eureka!

I got my test environment up with PHP5 and was able to dupe Claudio's error. Backing everything back to array notation (not object notation) and giving Andrews seemingly irrelevant suggestion a try, it went away. Goes to show you what I know. The code in question is attached.

Anyone want to give it a shot?

atreides-1’s picture

Dan, Andrew ...

I'm just back from being one week away, and I've just tested the subscriptions_12.module patch. It seems to work perfectly, and I'm not getting any kind of errors. I think it is everything solved, though I still want to test it a little bit more.

What is clear, is that previous errors don't appear anymore, and that all seems to be working perfectly.

Thanks to both of you!

dziemecki’s picture

Status: Needs review » Fixed

Fixed code committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)
meba’s picture

Status: Closed (fixed) » Active

Reopening as this bug exists also there:

    $result = db_query('SELECT status FROM {node} WHERE nid = %d', $content['nid']);

on line 490

and i think there (not sure):

    $result = db_query('SELECT pid, status FROM {comments} WHERE cid = %d', $content['cid']);

on line 487

and there (not sure):

  $result = db_query('SELECT tid FROM {term_node} WHERE nid = "%s"', $comment['nid']);

on line 530

dziemecki’s picture

Status: Active » Needs review
StatusFileSize
new47.61 KB

I've made the related lines version agnostic. Please test the attached and let me know if that works for you.

dziemecki’s picture

Status: Needs review » Fixed

Been quiet for a month. Marking this one "Fixed"

dziemecki’s picture

Corrected code committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)