I got the error

Fatal error: Cannot unset string offsets in /var/www/drupal/sites/all/modules/cck/content.module on line 124

This fatal error prevents to create or edit nodes of the affected content type, so this is a major issue. I got this error with fields generated by node reference

More context information: http://drupal.org/node/989254

I did a small patch to prevent this error.

Enjoy IT

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

-enzo-’s picture

Typo the line is 1248

dagmar’s picture

Status: Active » Needs work
-    unset($items[$field['field_name'] .'_add_more']);
+    if(isset($items[$field['field_name'] .'_add_more']))
+        unset($items[$field['field_name'] .'_add_more']);

http://drupal.org/coding-standards#indenting Use two spaces instead of tabs.

http://drupal.org/coding-standards#controlstruct use {} in control structures. Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls.

http://drupal.org/coding-standards#concat Always use a space between the dot and the concatenated parts to improve readability.

And from http://drupal.org/node/34341 use !empty() instead of isset()

So, the code should be:

if (!empty($items[$field['field_name'] . '_add_more'])) {
  unset($items[$field['field_name'] . '_add_more']);
}   
Gemma Morton’s picture

FileSize
662 bytes

Iv rolled the patch to use whats shown in #2.

Is this going to be accepted?

Gemma Morton’s picture

FileSize
704 bytes

Me again,

It seems the Addresses module sends the following array to _content_field_invoke for $items:

... (Object) stdClass
data (Array, 1 element)
  0 (Object) stdClass
    data (Array, 5 elements)
      street (Object) stdClass
      city (Object) stdClass
      province (Object) stdClass
      postal_code (Object) stdClass
      country (Object) stdClass
  type (String, 6 characters ) struct
type (String, 5 characters ) array

Whilst the code expects an Array, this is throwing numerous errors on my site (and thus I am sure others)

Fatal error: Cannot use object of type stdClass as array in modules/cck/content.module on line 1248

So, Iv just changed the patch to first check if it is an Array, before unsetting $items[_add more]

I realise that at the end of this day, this is something that Addresses should check, but its probably a good idea for CCK to make sure its checking an array, before it trys to do anything to it. I hope this is ok.

Gemma Morton’s picture

Ignore my comments.

In your code, you should run
node_object_prepare($node);

before
node_save($node);

and then you shouldnt receive this error.

jessia’s picture

When I try to apply this patch, I get the error:

patching file content.module
patch: **** malformed patch at line 15:

-Jessi

Ludo.R’s picture

I have the same issue on line 1248.

It may be linked to this issue : http://drupal.org/node/1077798

kenorb’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.