Unsupported operand types
giorez - September 24, 2009 - 19:15
| Project: | Link |
| Version: | 6.x-2.7 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | jcfiala |
| Status: | closed |
Description
Fatal error: Unsupported operand types in /sites/all/modules/link/link.module on line 362

#1
I have committed a fix for this issue. Could you please test and confirm.
#2
now it works
#3
great
#4
Didn't work for me. Ik got the same error on line 367.
Had link 2.6 installed, replaced it with link 2.x-dev version. I checked update.php but no updates were required. Went to a Views page with a list of nodes which use link fields: got the operand error.
#5
netsensei: could you please export your view and content type to see if I can reproduce the bug ?
#6
I have also same error :
Fatal error: Unsupported operand types in /home/drupal/drupal/sites/all/modules/link/link.module on line 367
Here is my Views code :
$view = new view;$view->name = '_content_affiliates';
$view->description = 'Extract affiliates from Content';
$view->tag = 'SR_content';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'field_affiliates_opodo_url' => array(
'label' => 'AffiliatesOpodo',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_affiliates_opodo_url',
'table' => 'node_data_field_affiliates_opodo',
'field' => 'field_affiliates_opodo_url',
'relationship' => 'none',
),
'field_affiliates_thalasseo_url' => array(
'label' => 'AffiliatesThalasseo',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_affiliates_thalasseo_url',
'table' => 'node_data_field_affiliates_thalasseo',
'field' => 'field_affiliates_thalasseo_url',
'relationship' => 'none',
),
'field_affiliates_hotels_url' => array(
'label' => 'AffiliatesHotels',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_affiliates_hotels_url',
'table' => 'node_data_field_affiliates_hotels',
'field' => 'field_affiliates_hotels_url',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'nid' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'node',
'default_argument' => '',
'validate_type' => 'node',
'validate_fail' => 'empty',
'break_phrase' => 0,
'not' => 0,
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'image' => 0,
'panel' => 0,
'base_content_type' => 0,
'beach' => 0,
'divingcenter' => 0,
'divingsite' => 0,
'golf' => 0,
'hotel' => 0,
'page' => 0,
'restaurant' => 0,
'story' => 0,
'test' => 0,
'tourism' => 0,
'villa' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'4' => 0,
'5' => 0,
'8' => 0,
'7' => 0,
'6' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_php' => '',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Affiliates');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
$handler->override_option('pane_title', '');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
'name' => 'View panes',
'weight' => 0,
));
$handler->override_option('allow', array(
'use_pager' => FALSE,
'items_per_page' => FALSE,
'offset' => FALSE,
'link_to_view' => FALSE,
'more_link' => FALSE,
'path_override' => FALSE,
'title_override' => FALSE,
'exposed_form' => FALSE,
));
$handler->override_option('argument_input', array(
'nid' => array(
'type' => 'panel',
'context' => 'node.nid',
'panel' => '0',
'fixed' => '5',
'label' => 'Node: Nid',
),
));
$handler->override_option('link_to_view', 0);
$handler->override_option('inherit_panels_path', 0);
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '_content_affiliates_block');
$handler->override_option('block_caching', -1);
#7
Can you confirm that this happens with the current dev version ? I can not reproduce the bug. Could you please try with the most recent dev version and confirm. Thanks.
#8
Yes it happens with 6.x-2.x-dev version
#9
I get the same error in line 367 as well.
I just installed the dev version (no version ever installed before) and created a new content type (test) with just the link field.
Required field, no title, nofollow, open in new window.
Created a node of type test - Entered the url and previewed - Error displayed.
If I save it seems ok, displays fine if I view or edit the node. If I edit and preview again - It errors.
Unsupported operand types in .../sites/all/modules/link/link.module on line 367
#10
Ok... I know very little PHP but it seems to me that on line 360 if item['attributes'] is not an array then you unserialize it and assume that it will be array after that. I took a guess that maybe that is not the case and stuck the following in
if (!is_array($item['attributes'])) {
$item['attributes'] = array();
}
So Line 359 onwards becomes..
if (!is_array($item['attributes'])) {
$item['attributes'] = unserialize($item['attributes']);
if (!is_array($item['attributes'])) {
$item['attributes'] = array();
}
}
I no longer get an error when previewing and things 'seem' ok.
No idea if that is the right fix for the right problem but maybe it gives a clue. item['attributes'] is not an array when you do the +=
Andy
#11
Andy, I agree but I think its not the problem of "unserialize", in my opinion it should be tested that $item['attributes'] does exist.
So I patched to (near by line 359)
// NEW: check if is set
if (!isset($item['attributes'])) {
$item['attributes'] = array();
}
// Unserialize attributtes array if it has not been unserialized yet.
if (!is_array($item['attributes'])) {
$item['attributes'] = unserialize($item['attributes']);
}
#12
I had committed a fix for this. Please test.
Thank you guys.
#13
I'm now getting this error with brand new version 6.x-2.7. I see that the changes discussed above have already been made in this version. I'm getting the error on line 371, which is
<?php$item['attributes'] += $field['attributes'];
?>
#14
The problem seems to be that if $item['attributes'] is set to an empty string, unserializing it doesn't make it an array. :-)
I changed line 364 to
<?php$item['attributes'] = (array)unserialize($item['attributes']);
?>
and the error went away.
#15
Subscribing #14 seems to work for me
#16
I can confirm the bug. And the fix works.
#17
Just wanted to confirm I too have encountered the bug mentioned in #13: PHP Fatal error: Unsupported operand types in sites\all\modules\link\link.module on line 371
The fix suggested in #14 on line 364 has worked for me as well.
#18
thanks BenStallings :-)
#19
Whups. I'll take a look at that when I get home, plug it in, and do a little testing. Sounds like 6.x-2.8 might be coming out soon, sorry folks.
#20
The following patch solves the issue for me, but I took a different approach than in #14.
I think the error occurs, because
+=should only be used for arithemtic operations and not for arrays.So I changed
<?php$item['attributes'] += $field['attributes'];
?>
to
<?php$item['attributes'][] = $field['attributes'];
?>
and
<?php$field['attributes'] += _link_default_attributes();
?>
to
<?php$field['attributes'][] = _link_default_attributes();
?>
#21
BenStallings (#14) patch worked for us, cheers!
#22
I did as #20 but I ended up with
warning: preg_match() expects parameter 2 to be string, array given in /home/content/t/h/e/thesignforum/html/includes/bootstrap.inc on line 777.
#23
Did as 14 suggested and the error went away thanks
#24
implemented fix from #14 -- line 371 -- and the problem appeared to resolve.
however, i then went in to edit one of the affected nodes containing a (single) link, at which point i get (multiple instances of) this warning:
warning: unserialize() expects parameter 1 to be string, array given in /Users/me/Sites/client/sites/all/modules/link/link.module on line 371.
it doesn't stop me from updating the node, but it does suggest this fix isn't sufficient.
i'm using a link with a static title and rel=nofollow.
#25
So, I threw together a quick and dirty test here, and I'm not having this error with a standard link field... unless I'm displaying that field in a view, as a field. Does this duplicate what other people are seeing?
#26
Okay folks - I've just speed-released a 6.x-2.8 version of Link that implements BenStallings' patch in #14.
Thanks, and sorry for the code breaking there.
This is why I need to spend some time making some automated tests on link.
#27
I tested the current version with the fix from #14 applied, and is working Ok for me, displaying the full node, and displaying the field in a view.
#28
#29
+= is a valid arrays operator in PHP. The problem was that one of the parameters in question was not an array.
#30
This does not need review.
This is now fixed in link-6.x-2.8 - download it and see.
#31
new 2.8 update fixes issue for me.
thank you so much!!
#32
2.8 works fine also for me.
Thank you very much for the quick fix!
#33
Confirming that 2.8 works for me as well (my original post was #17), thanks much for the quick fix :)
#34
2.8 worked for me, as well. Thank you for being so quick!
I'm adding this comment because the problem didn't appear for me until I enabled workflow on a content type. My initial searches included the words "drupal" and "workflow" an so this thread did not come up. If anyone else experiences the same thing, hopefully this thread will come up for them now.
#35
I ipdated link module to 2.8 but i still got a error when bulk updating url aliases.
This is the error:
Fatal error: Unsupported operand types in /home/drupalcamp/default_www/sites/all/modules/link/link.module on line 368#36
This ticket has gotten a bit long, and has been applied to a number of versions, so I'm splitting it off into #626932: Unsupported Operand Types - Bulk URL Aliases to help keep things organized. betz, if you could respond there with more details? Thank you.