The Fatal error of:
Cannot use string offset as an array
Still persists in ncck. Copying the temporary solution from the video_cck thread:
I'm not sure my method is ok, but the problem was with that line :

$node->$field_name[$delta]['data'] = $data;

I fixed it using an intermediary variable ($nodefield) :

    if ($field['multiple']) {
      foreach ($items as $delta => $item) {
        $data = (array)unserialize($items[$delta]['data']);
        $nodefield = $node->$field_name;
        $items[$delta]['data'] = $data;
        $nodefield[$delta]['data'] = $data;
      }
    }

Comments

Souvent22’s picture

It seems that some version of PHP do not decouple well; meaning going to from obj. to array, etc.
Example, the following code set throws the string off set error:

      $data = (array)unserialize($items[0]['data']);
      $items[0]['data'] = $data;
      $node->$field_name[0]['data'] = $data;

However, this code does not:

      $data = (array)unserialize($items[0]['data']);
      $items[0]['data'] = $data;
      $temp = $node->$field_name;
      $temp[0]['data'] = $data;
      $node->$field_name = $temp;

Almost exactly the same except I take out the entire array and then place it back as a whole. I haven't found the exact reason why this is yet; but i've tested it a lot, and this seems to be the cause of it.
For reference, I'm using:

PHP 5.2.3
Windows
Apache 2.2
xDebug enabled

karens’s picture

Status: Active » Needs review
StatusFileSize
new1.09 KB

Using $node_field is the right approach, that's the way it's done in CCK core. Need to make the same fix in the non-multiple value code and apply it back to the $node object. A patch is attached that I think will do it.

ayolassan’s picture

This patch is working perfectly
Tks a lot

karens’s picture

Project: » Embedded Media Field
Version: » 5.x-1.x-dev

I'll move this to the new project.

Souvent22’s picture

StatusFileSize
new1.07 KB

Rolled a new patch

edwardrapley’s picture

Maybe the patch was not quite right, i had to add an } on line 161 and remove one on line 177. Then it worked fine. But i was patching manually so maybe i made the mistake.

robloach’s picture

I was experiencing this issue, and the patch you created seemed to fix it. Strange issue. Anyone know why this was happening? Probably has to do with PHP casting the values incorrectly or something.

jtorres543’s picture

My approach took 1 less line but I came to the same result. I don't know if there are any performance implications (I assume it would be negligible).

        $node_field_name = &$node->$field_name;
        $node_field_name[$delta]['data'] = $data;

This is caused by a change in PHP5 http://www.php.net/manual/en/migration5.incompatible.php

According to PHP.net it is a "bad habit" that will no longer be supported.

jtorres543’s picture

I misspoke, It is the same amount of code but it seems to me that mine should be correct as the original code would not modify the $node->field_name, but rather, a copy of it.

boris mann’s picture

Same error on PHP5 with this:

$data = (array)unserialize($items[0]['data']);
$items[0]['data'] = $data;
$node->$field_name[0]['data'] = $data;

However, I just wrapped field_name in curly brackets and it works:

$node->{$field_name}[$delta]['data'] = $data;
mamasdiner’s picture

Boris,
Your fix worked for me.
Thanks!
Heather

TX1121’s picture

it seemed to work fine for me when going into the original emfield.module file and puting "{" before and after $field_name.

aaron’s picture

Thanks for the work! Sorry I was unavailable the last few weeks -- I was moving out of state. I'll take a look at the patches and roll them in by early next week. (Still unpacking boxes this weekend.)

It must be a PHP5 thing -- I don't experience this in PHP4. I don't have PHP5 installed locally yet, and don't plan to until I start helping with D7 development. From the thread, though, it looks like this is a sounder solution anyway. Meanwhile, once I make sure the patch doesn't break in PHP4, will one of you be willing to test in PHP5 once the patch is in just to make sure?

Thanks,
Aaron

drumchef’s picture

I can confirm that the code Boris provided works with PHP5. Thanks!

green monkey’s picture

thank you for this patch

aaron’s picture

Status: Needs review » Fixed

Thanks for the help with this! I don't have php5 installed yet, but this all works w/ php4. I just put the curly brackets around $node->{$field_name} as Boris suggested in the two lines they appeared. After the repository synchs, could someone using php5 confirm this release works? I'll make sure to use this coding standard in the future.

Thanks,
Aaron Winborn

dsp1’s picture

i was having an error that was different. When trying to view a node that had the video field I would get a blank screen.
the log would show this entry:
include_once(./themes/engines/phptemplate/phptemplate.engine) [function.include-once]: failed to open stream: No such file or directory in /Users/ddp/Sites/drupal/includes/theme.inc on line 78.

Boris, this fixed my error too.

Drupal 5.1, PHP 5.22, CCK 1.5

Anonymous’s picture

Status: Fixed » Closed (fixed)