User login

Cannot use string offset as an array problem caused by not using curly brace brackets around variable

Why this weirdness?

cannot use string offset as array
Fatal error: Cannot use string offset as an array in /sites/jonassoftware/www/sites/all/modules/field_placement/field_placement.module on line 706

<?php
function field_placement_node_save(&$node) {
  $nid = $node->nid;
  $type = $node->type;
  $type_definition = content_types($type);
  $cck_fields = array_keys($type_definition['fields']);
  $delta = 0;  // used in hack below, if hack survives will replace with foreach
  foreach($cck_fields as $field_name) {
// hacky solution
    if ($field_values = field_placement_hack_pass_field_values()) {
dsm('patyblack');
dsm($node->$field_name);
dsm($field_values);
dsm($field_values[$field_name]);
//      if (isset($node->$field_name[$delta]['field_placement'])) {
//        $node->$field_name[$delta]['field_placement'] = $field_values[$field_name]['field_placement'];
//      }
      if (isset($node->$field_name[$delta])) {
//        $node->$field_name[$delta]['field_placement_imagecache'] =
        $test = $field_values[$field_name]; // ['field_placement_imagecache'];
      }
    }
// end hacky solution
?>

#

patyblack

#

Array
(
[0] => Array
(
[flags] => Array
(
[delete] => 0
)

[alt] =>
[title] => drupalgeonames_crop.jpg
[filename] => drupalgeonames_crop.jpg
[filepath] => sites/default/files/product_images/drupalgeonames_crop_8.jpg
[filemime] => image/jpeg
[filesize] => 85652
[fid] => 148
[field_placement] =>
[field_placement_imagecache] =>
)

)

#

Array
(
[field_placement] => 2
[field_placement_imagecache] => 5
)

Problem identified:

<?php
dsm('failure: ');
dsm($node->{$field_name}[$delta]);
?>

second line there printed blank-- no array.

new version with brackets:

<?php
function field_placement_node_save(&$node) {
  $nid = $node->nid;
  $type = $node->type;
  $type_definition = content_types($type);
  $cck_fields = array_keys($type_definition['fields']);
  $delta = 0;  // used in hack below, if hack survives will replace with foreach
  foreach($cck_fields as $field_name) {
// hacky solution
    if ($field_values = field_placement_hack_pass_field_values()) {
      if (isset($node->{$field_name}[$delta]['field_placement'])) {
        $node->{$field_name}[$delta]['field_placement'] = $field_values[$field_name]['field_placement'];
      }
      if (isset($node->{$field_name}[$delta]['field_placement_imagecache'])) {
        $node->{$field_name}[$delta]['field_placement_imagecache'] = $field_values[$field_name]['field_placement_imagecache'];
      }
    }
// ...
  }
// ...
}
?>

Resolution

Searched words: 
string offset curly brackets braces

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.