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'];
}
}
// ...
}
// ...
}
?>
Comments
Post new comment