I was importing a bunch of nodes 6.x nodes (using 6.x-3.1) into 7.x (using 7.x-3.x-dev) and kept hitting this error:

Fatal error: Cannot unset string offsets in sites/all/modules/contrib/node_export/node_export.module on line 718

This is line 718 (with some context):

if (variable_get('node_export_reset_path_' . $node->type, TRUE)) {
      $node->path = NULL;
    }
    else {
      unset($node->path['pid']); // Line 718

I made two discoveries:

  1. The nodes I was importing did not have $node->path['pid'], only $node->path.
  2. PHP throws an error when you try to treat a string like an array, as with unset().

Assuming, then, that if it exists, $node->path['pid'] should be a string (which makes sense) the attached patch resolves the error.

Comments

venutip’s picture

Status: Active » Needs review
dwaine’s picture

After updating from 6.x-2.24 to 6.x-3.1 my site is seeing this same issue while testing the node import process. The exact message is:

Fatal error: Cannot unset string offsets in \sites\all\modules\node_export\node_export.module on line 626
danielb’s picture

Can you see if this works as a replacement for line 718 in node_export.module ? If it does I would prefer to do it like this.

<?php
if (isset($node->path['pid'])) {
  unset($node->path['pid']);
}
?>
venutip’s picture

Hi danielb,

Tried your fix and still hit the same error. The problem is that (for all my nodes, anyway) $node->path is a string, not an array, so PHP thinks we're trying to access the string using array notation, and so always returns the first letter of $node->path.

How about this patch?

danielb’s picture

Tried your fix and still hit the same error.

I don't believe you.

danielb’s picture

But seems you're right

> The problem is isset($options['messages']) returns true even though
> $options is the string '/^[a-z]/i'. Inside isset(), PHP casts 'messages' to
> an int, so it's the same as isset($options[0]), which is the character '/'!
> Since the isset passes, unset fails because you can't unset a character
> from a string.

http://www.magentocommerce.com/boards/viewthread/261346/

blooody php

danielb’s picture

Status: Needs review » Fixed

Committed something similar to your patch :)

Thanks!

venutip’s picture

Ha ha, glad you decided I was not lying to you :)

Thanks!

chromix’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Fixed » Patch (to be ported)

We need to have this same fix back-ported to 6.

chromix’s picture

...and here it is. Test in good health.

chromix’s picture

sorry... this one fixes the extra spaces at the end of one of the lines (git will complain about it)

danielb’s picture

Status: Patch (to be ported) » Fixed

cheers, committed

Status: Fixed » Closed (fixed)

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

opdavies’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

I'm getting a similar error:

Fatal error: Cannot unset string offsets in /home/odavies/unionlearn/drupal/modules/menu/menu.module on line 543

This only happens when I uncheck the option to reset menu links for this content type.

I'm using the 7.x-3.x-dev branch with Drupal 7.12.

opdavies’s picture

Status: Closed (fixed) » Active

This seems to be specific to the XML output. I've exported the content using the Node Code format, and it's importing OK, including the menu items.

If I'm able, then I'll post both versions of the exported code here.

danielb’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Active » Closed (fixed)

Please don't hijack issues. The same error message is not grounds for reopening, and in this case it isn't even the same.