I get this error message when trying to view a profile page:

Object of class stdClass could not be converted to string in /home/.kalmuk/personman/drupal/sites/all/modules/favorite_nodes/favorite_nodes.module on line 92.

It actually displays about 20 times in the same box. Here's my line 92:

natcasesort($node_types);

I just commented it out and things seem to work fine. I hope that sort isn't vital.

I'm using php 5.2.2

CommentFileSizeAuthor
#6 favorite_nodes.patch2.01 KBAnonymous (not verified)

Comments

rootwork’s picture

I was getting the same thing, on line 147 (which calls the same function):

natcasesort($node_types);

I also commented it out and seem to have suffered no ill effects...googling for this error shows a lot of similar issues in many modules, apparently all related to PHP 5.2. This is probably the most helpful post for the module maintainer to address this issue.

stefgosselin’s picture

Same issue here, php 5.2 install. Seems on this install the file menu.inc:

Object of class stdClass could not be converted to string in /home/boutique/public_html/includes/menu.inc on line 1026.

Line 1026, on menu.inc:

return strnatcasecmp($a['title'], $b['title']);

--------------------------------------------------------------------------------

Seems strbatcasecmp is the culprit as all or most of about a dozen related issues similar to mine found on a quick google point to strnatcasecmp, furthermore ... there are syntactic differences in PHP as of 5.2 wich although minor could be affecting certain drupal installs.

At first glance, commenting out the return value of this function seems kind of ,... not proper.
I will be trying to look into a better solution, meanwhile if anyone has a clue, plz post so here ?

stefan vaduva’s picture

I'm also interested in a solution for this

Anonymous’s picture

it is because you are getting an array of objects, instead of just an array. see this:

$node_types = node_get_types();
$node_types_keys = array_keys($node_types);
unset($node_types);
foreach($node_types_keys as $node_type_key) {
$node_types[] = $node_types[$node_type_key]->type;
}

natcasesort($node_types);

Ill submit a proper patch later.

Rain City Studios

alexrayu’s picture

Thanks for the explanation. Also, wonderful module - very useful.
I see what the above mentioned code is trying to do, but it has not worked for me. Upon unsetting the $node_types, this array is no longer repopulated.
$node_types[] = $node_types[$node_type_key]->type; - after carrying out this function for each of the keys, the $node_types array remains empty. print_r($node_types) shows that the values are empty.
Has anybody who tried this succeeded?

Anonymous’s picture

Assigned: Unassigned »
Status: Active » Needs review
StatusFileSize
new2.01 KB

The simplest way to fix this issue, AFIK, is to just comment out the two places for the natcasesort function, which is a native php function which does as it says, do a natural case sort of an array. If commenting out these lines solves your problem, do it and go back to sleep.

I asked someone else about this module and he said that the functionnality of favorites_node is replaceable by Views Bookmarks.

I had offered my last post quickly before running out of here, so although I dont have all the answers yet, lets get a little further into this. Please note I am writing this without having all the pieces in place.

For testing I grabbed a clean copy of Drupal 5-3 from CVS and the favorites_node module. I added one story and one page of content. I added the module, enabled it and put it in a block. The error I get is this:
: Object of class stdClass could not be converted to string in /opt/lampp/drupal53/public_html/modules/favorite_nodes/favorite_nodes.module on line 167.
: Object of class stdClass could not be converted to string in /opt/lampp/drupal53/public_html/modules/favorite_nodes/favorite_nodes.module on line 167.

The error is reporting an error from the natcasesort function call expecting an array.
If in the function call in the line before it returns an array of objects, it wont be able to read it and will then return an error.

Which line the error reports seems to depend on what you are doing with Drupal at the time, with respect to User credentials and roles, module permissions and whether or not the module is publicly seen in a block. But it is always because natcasesort cant handle objects as array elements. So my first try to fix this problem was partially right. But node_get_types(), as best as I can tell, can return either arrays of strings or arrays of objects. It is in the core and is not for us to think about.

So back in favorites_node.module, between lines that say this:

$node_types = node_get_types();
natcasesort($node_types);

Please add the following:

if(is_array($node_types)){
$object_test = false;
$node_types_keys = array_keys($node_types);
$node_types_temp = array();
foreach($node_types as $node_type_element) {
if(is_object($node_type_element)) {
$object_test = true;
$node_types_temp[] = $node_type_element->type;
}
}
if($object_test == true) {
$node_types = $node_types_temp;
unset($node_types_temp);
}
}

OR BETTER YET use the patch I have provided.

What does it do? Check to see if the value is an array. then it checks to see if the array elements have objects. If so, we create a temporary array that has the names of the nodes from the object that we really want, we clear the old array and assign the new data back to that array so the rest of the code can handle it.

The extra checking for array, objects, is because Alexi Rayu still had a problem after my first fix. His instance of Drupal does not seem to return an array of objects.

The intention with the code above is to do a bit of additonal checking to prevent things being messed with if the value of $node_types is either not an array or its arrays do not contain objects.

Please test. thanx.

wolfderby’s picture

Status: Needs review » Fixed

I had this problem and updated to the latest version of favorite_nodes and it seems to be working fine now.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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