Codes like

    foreach ($nodes as $node) {
        $node = node_load(array('nid' => $node->nid)); 

when used in php 5.3 does not return anything - blank comes.
This workks fine with php 5.2x

How can I make or write something alternative to it to work in php 5.3

Comments

barrett’s picture

That code works just fine for me in PHP 5.3. Are you sure you $nodes array isn't empty and that it's contents are node objects?

Also, what's the purpose of what you're doing with that code? If you already have an array of node objects why are you trying to reload them?

yeti22’s picture

Thanks Barrett.
This is contained in the file class_album.inc ( album images )
When I change the server to use php5.2x it works just fine, when I change to 5.3 it does not.
Do you think this small piece can be coded in an altered way to work?

barrett’s picture

Okay, so this is a problem you're having with the Acidfree Albums module? What version?

[edit]
Nevermind, it looks like that file only exists in version 5, so I assume that's what you're using.

Assuming there's nothing helpful in your log files, the first thing I'd do to start trying to fix the issue is post in their issue queue. That may not get you any help, since Drupal 5 is no longer supported.

If the issue queue doesn't get an answer for you, I'd start by dumping input variables to the screen to see what the loop is taking in. The code below will dump the content of the $nodes array to a drupal message for you.

    drupal_set_message("Nodes array is" . print_r($nodes, TRUE));
    foreach ($nodes as $node) {
        $node = node_load(array('nid' => $node->nid));
        $output .= theme("acidfree_print_thumb_{$node->type}", $node, $term)."\n";
    }
yeti22’s picture

This looks like solid help so thanks again Barret. But I am not getting any output.
That is Nodes array is [blank]

Irrespective of obsolete album script or obsolete drupal I am wondering what small thing is contained in
$node = node_load(array('nid' => $node->nid)); so that it works fine in php 5.2x but not in php 5.3
Anything to do with tweaking php.ini to combat some newness in php 5.3 or anything small to use instead of node_load(array, just any other equivalent function?

Edited now

I just got this Nodes array

Nodes array isArray ( [0] => stdClass Object ( [nid] => 2133 [node_sticky] => 1 ) [1] => stdClass Object ( [nid] => 2141 [node_sticky] => 0 ) [2] => stdClass Object ( [nid] => 2140 [node_sticky] => 0 ) [3] => stdClass Object ( [nid] => 2139 [node_sticky] => 0 ) [4] => stdClass Object ( [nid] => 2138 [node_sticky] => 0 ) [5] => stdClass Object ( [nid] => 2135 [node_sticky] => 0 ) [6] => stdClass Object ( [nid] => 2134 [node_sticky] => 0 ) [7] => stdClass Object ( [nid] => 2094 [node_sticky] => 0 ) ) 

So can you please do a little bit of hand-holding to say what do I do now?

mwheinz’s picture

If node_load(array()) isn't working for you, you should be experiencing much bigger problems than just with acidfree - node_load() is the basic function for loading any node in a drupal site:

function node_load($param = array(), $revision = NULL, $reset = NULL)

So, if node_load() was broken, you'd be seeing all sorts of issues.

Much more likely is that $node->nid is not being populated correctly - but the comment you posted at http://drupal.org/node/1096120#comment-4226142 looks right.

Try this as well:

<?php
    foreach ($nodes as $node) {
        drupal_set_message("Nid is: " . $node->nid);
        $node = node_load(array('nid' => $node->nid));
        $output .= theme("acidfree_print_thumb_{$node->type}", $node, $term)."\n";
    }
?>
yeti22’s picture

Hello mwheinz, this is to say just a quick thank you while I try, re-test and try to dive deeper.
It looks like awesome help here!

node_load is indeed working as "Views" also has this and Views outputs are apparently working just as fine in php 5.3. The problem seems node_load and (array('nid side by side as in this .inc file.

I will try to follow the advices gathered and solve this as I think many more users will also be stuck just simply due to this 1 line in future.

Edited:

Your code gives

Nid is: 2133 
Nid is: 2141 
Nid is: 2140 
Nid is: 2139 
Nid is: 2138 
Nid is: 2135 
Nid is: 2134 
Nid is: 2094 

However thumbnails do not show up.

barrett’s picture

Okay, so your array is good. The next step is to do the same, but with the output of the node_load. I expect this is going to be fine, but just to be safe, replace the previous code with...

    foreach ($nodes as $node) {
        $node = node_load(array('nid' => $node->nid));
        drupal_set_message("Node  is " . print_r($node, TRUE));
        $output .= theme("acidfree_print_thumb_{$node->type}", $node, $term)."\n";
    }

If the previous code doesn't show problems, do the same but with what's coming out of the theme function.

    foreach ($nodes as $node) {
        $node = node_load(array('nid' => $node->nid));
        $new_output = theme("acidfree_print_thumb_{$node->type}", $node, $term)."\n";
        $output .= $new_output;
    }
yeti22’s picture

<?php
    foreach ($nodes as $node) {
        $node = node_load(array('nid' => $node->nid));
        drupal_set_message("Node  is " . print_r($node, TRUE));
        $output .= theme("acidfree_print_thumb_{$node->type}", $node, $term)."\n";
    }
?>

The above code gives a very detailed output to the screen (some private informations I have removed) which most excitingly contains the image file names like files/images/leaves.jpg. This output is like

# Node is stdClass Object ( [nid] => 2074 [vid] => 2147 [type] => image [status] => 1 [created] => 1250843934 [changed] => 1250843936 [comment] => 2 [promote] => 0 [sticky] => 0 [revision_timestamp] => 1250843936 [title] => aaaa... [body] => [teaser] => [log] => [format] => 1 [uid] => 81 [name] => xyz [picture] => files/pictures/picture-81.jpg [data] => ;s:6:"format";s:1:"1";s:8:"og_email";s:1:"1";} [images] => Array ( [_original] => files/images/Snake.jpg [thumbnail] => files/images/Snake.thumbnail.jpg [preview] => files/images/zz.preview.jpg [thumb_for_profilepage] => files/images/zz.thumb_for_profilepage.jpg ) [rebuild_images] => [simple_access_owner] => Array ( [sa_view] => 0 [sa_update] => 0 [sa_delete] => 0 ) [simple_access] => Array ( ) [0] => [last_comment_timestamp] => 1250919351 [last_comment_name] => [comment_count] => 6 [taxonomy] => Array ( [132] => stdClass Object ( [tid] => 132 [vid] => 1 [name] => abc's album [description] =>
[weight] => 0 ) ) )

and much more in the same manner.

However the next code that is

<?php
    foreach ($nodes as $node) {
        $node = node_load(array('nid' => $node->nid));
        $new_output = theme("acidfree_print_thumb_{$node->type}", $node, $term)."\n";
        $output .= $new_output;
    }
?>

returns blank.

Just scratching my head on two grounds
- what is so mysterious about node_load(array particularly when node_load works fine in Views etc
- is there any way to force drupal_set_message("Node is " . print_r($node, TRUE)); to give a thumbnailed output?

barrett’s picture

The issue with the second hunk of code not outputting anything is that I omitted the line which would cause it to output. The code should have been...

    foreach ($nodes as $node) {
        $node = node_load(array('nid' => $node->nid));
        $new_output = theme("acidfree_print_thumb_{$node->type}", $node, $term)."\n";
        drupal_set_message($new_output);
        $output .= $new_output;
    }
Just scratching my head on two grounds
- what is so mysterious about node_load(array particularly when node_load works fine in Views etc
- is there any way to force drupal_set_message("Node is " . print_r($node, TRUE)); to give a thumbnailed output?

The answers to these questions are:
- node_load is working just fine, as witnessed by the output you saw when print_r'ing the loaded node.
- nope, print_r just dumps data, it doesn't do any formatting. See http://php.net/manual/en/function.print-r.php for more information

The problem, as was suspected, is not in node_load but in the theme function. Try walking through that function doing the same kind of print_r dumping as we did for the calling piece of code.