Download & Extend

Cannot use a scalar value as an array error

Project:Service links
Version:7.x-2.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Upgraded a site an I got a bunch of the following errors:

warning: Cannot use a scalar value as an array in /home/[site]/public_html/sites/all/modules/service_links/service_links.module on line 539.

Disabling an re-enabling certain services made it go away; possibly one of the services is now obsolete? If so, it's a useful message, but shouldn't appear for anonymous users.

In any event, I thought I'd post this in case somebody else runs into the same problem. All OK now.

Comments

#1

Upgraded... so from 1.x to 2.x?

#2

You know, I'm not sure - I upgraded via Drush and insofar as 1.x is no longer available, that could have been the case.

#3

Remove the Blog content type checkmark from services links. Then try to look for the errors in your database (is your Blog still a blog in D7?)

#4

Correction. I had to re-enable the general services, print services and printer-friendly pages modules. THen I could enable service links in blog posts.

#5

Also, the new service links module has moved the service links types (General, Print, Farsi Etc.) out of the main box in D7.

Subtle error with a simple albeit strange solution. Woo DrupalCon 2012

#6

Coming from #1303462: Cannot use a scalar value as an array in _service_links_render() and looking for a fix for the D6 version; this discussion seems to target upgrades to the D7 version?

#7

i guess is almost the same problem he started from 6.x-1.x to 6.x-2.x, and you started from 6.x-2.0 to 6.x-2.1... then drush forget to do something... have you tried to clean the cache?

#8

Yes, sure, several times.

#9

Looking to resolve this issue for D7, using latest Services Link update.

Seems related to showing services icons on teaser (links area). When disabling service links for teaser, error disappeared. ...but so do the services links -- even though they are configured to show on full node view.

#10

@both: what version of Drupal are you using? Made some theme customizations or using the APIs elsewhere?

#11

In my case: Pressflow 6.22, no theme customizations related to service links module, and no useage of it's API.

I can reproduce the warning WD php: Warning: Cannot use a scalar value as an array in _service_links_render() (line 5xx of /var/www/drupal/sites/all/modules/service_links/service_links.module). on several sites when running drush search-index (line 5xx refers to lines 543-558). Maybe you could try to reproduce this? drush 3.3 is even in Debian's repository; running PHP 5.3.3-7+squeeze3 with Suhosin-Patch.

#12

Category:bug report» support request

made all the tests from scratch and i confirm, the error disappear after cache clean + saving the list of services again

#13

Status:active» reviewed & tested by the community

Confirming; the procedure from #12 seems to work.

#14

Saving the lists of services worked for me as well.

Site configuration -> Services links -> Services -> Save

#15

Just confirming that #12 and #14 worked for me too!
I simply believe that additional confirmation from someone who has faced the same issue will help validate that the suggested fix is working. Thanks Guys!

#16

Unfortunately that didn't work for me but I can shed some light on what's happening.

This return line in the function service_links_get_links() (shown below) has input arrays and a resultant array as attached, hopefully that will give the developer enough to know what's going on.

Essentially, every top level array element ends up with the scalar value of 1 except "google_one_plus" which has a value that's an array. All the non-array values produce the warnings.

Here's the line that the file of arrays is based around:
return isset($services) ? array_merge($services, array_intersect_key($links, $services)) : $links;

Below is the stack trace:
Warning: Cannot use a scalar value as an array
20  Line: 21,  File: /index.php,  Function: menu_execute_active_handler
19  Line: 503,  File: /includes/menu.inc,  Function: call_user_func_array
18  Function: views_page
17  Line: 455,  File: /sites/all/modules/views/views.module,  Function: execute_display
16  Line: 1080,  File: /sites/all/modules/views/includes/view.inc,  Function: execute
15  Line: 219,  File: /sites/all/modules/views/plugins/views_plugin_display_page.inc,  Function: render
14  Line: 1017,  File: /sites/all/modules/views/includes/view.inc,  Function: render
13  Line: 2294,  File: /sites/all/modules/views/plugins/views_plugin_display.inc,  Function: theme
12  Line: 858,  File: /includes/theme.inc,  Function: template_preprocess_views_view
11  Line: 45,  File: /sites/all/modules/views/theme/theme.inc,  Function: render
10  Line: 242,  File: /sites/all/modules/views/plugins/views_plugin_style.inc,  Function: render
9  Line: 101,  File: /sites/all/modules/views/modules/node/views_plugin_row_node_view.inc,  Function: node_view
8  Line: 1285,  File: /modules/node/node.module,  Function: node_build_content
7  Line: 1387,  File: /modules/node/node.module,  Function: module_invoke_all
6  Line: 819,  File: /includes/module.inc,  Function: call_user_func_array
5  Function: service_links_node_view
4  Line: 122,  File: /sites/all/modules/service_links/service_links.module,  Function: service_links_render
3  Line: 491,  File: /sites/all/modules/service_links/service_links.module,  Function: _service_links_render
2  Line: 580,  File: /sites/all/modules/service_links/service_links.module,  Function: _drupal_error_handler
1  Line: 2140,  File: /includes/bootstrap.inc,  Function: _drupal_error_handler_real
0  Line: 88,  File: /includes/errors.inc,  Function: _drupal_log_error

in _service_links_render() (line 580 of /sites/all/modules/service_links/service_links.module).
AttachmentSize
arrays.txt 4.49 KB

#17

Further information...

I just went to the services tab for the first time and Google Plus One was enabled but the rest were disabled.

I then enabled all and saved - errors went away.
I then disabled and saved - errors were still gone.
I then cleared the cache and reloaded a page - errors were still gone.

The conclusion is that somewhere in code it a bug of setting values before any values have been saved in the database.

Here is the $services array at line 403 as it's returned from the function service_links_get_links(), note that all the scalar values are gone (compared to as shown in the attached in the previous post - duplicated below):

Array as it is now:
array (
  'google_plus_one' =>
  array (
    'name' => 'Google Plus One',
    'link' => '<url>',
    'description' => 'Plus it',
    'javascript' =>
    array (
      0 => 'https://apis.google.com/js/plusone.js',
      1 => 'google_plus_one.js',
    ),
    'style' => 4,
    'callback' => 'ws_google_plus_one_data',
    'module' => 'widget_services',
  ),

Array as it was before saving with all services checked as enabled. Note: non-reproducible after that event.
array (
  'delicious' => 1,
  'digg' => 1,
  'stumbleupon' => 1,
  'twitter' => 1,
  'reddit' => 1,
  'newsvine' => 1,
  'facebook' => 1,
  'myspace' => 1,
  'yahoo' => 1,
  'linkedin' => 1,
  'technorati_favorite' => 1,
  'google_plus_one' =>
  array (
    'name' => 'Google Plus One',
    'link' => '<url>',
    'description' => 'Plus it',
    'javascript' =>
    array (
      0 => 'https://apis.google.com/js/plusone.js',
      1 => 'google_plus_one.js',
    ),
    'style' => 4,
    'callback' => 'ws_google_plus_one_data',
    'module' => 'widget_services',
  ),

#18

Version:6.x-2.x-dev» 7.x-2.1

#14 worked for me too.

#19

Version:7.x-2.1» 7.x-2.x-dev
Status:reviewed & tested by the community» fixed

Added a patch on dev, for 6.x and 7.x: everytime a module containing some service is disabled the related id is filtered and a message is shown suggesting what to do...

#20

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.