Getting the following error under PHP 5.4


This doesn't appear to break functionality but it does cause the warning to be displayed when editing or saving any node with a Hierarchical Selection field.

I've found that modifying lines 86 and 87 to the following suppresses the error:

//array_merge($element['#attributes']['class'], $classes);
$element['#attributes']['class'] = implode(',', $classes) . ' ' . implode(' ', $classes);
Members fund testing for the Drupal project. Drupal Association Learn more


Wim Leers’s picture

Title: Array to String Conversion in PHP 5.4 » PHP 5.4 compatibility of theme_hierarchical_select()
Category: bug » task
Status: Active » Needs work

That patch makes little sense to me.

Could you do a var_dump of $classes?

tregeagle’s picture

Status: Needs work » Reviewed & tested by the community

I can confirm this error under PHP 5.4
To clarify, when I use the Hierarchical Select widget to select a taxonomy item in the form I get the following error,

Notice: Array to string conversion in theme_hierarchical_select() (line 87 of /var/www/sites/default/modules/contrib/hierarchical_select/includes/

Here is the result of a $classes var_dump:

array(4) { [0]=> string(27) "hierarchical-select-wrapper" [1]=> string(43) "hierarchical-select-level-labels-style-none" [2]=> string(60) "hierarchical-select-wrapper-for-name-edit-field-category-und" [3]=> string(49) "hierarchical-select-wrapper-for-config-taxonomy-4" }

Thanks @Ignigena your patch fixed the issue for me.

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work

The patch is imploding with two different concatenators and with the exact same values. That doesn't make any sense.

Sorry, but I really can't commit this.

tregeagle’s picture

Status: Needs work » Needs review
1.26 KB

Hi Wim,

I know this is a very minor issue but I am learning so I asked a more savvy friend to help me work this out. @Ignigena's patch did not make sense to Matthew either so he suggested the attached patch.

It looks like the array_merge function doesn't do anything unless it has its value explicitly assigned.

Thanks Wim, for all your work on this neat module.

kurtzhong’s picture

This patch works fine, thanks.

Ignigena’s picture

The patch in #4 works great.

I don't know what I was smoking ... lol

rudiedirkx’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #4 is perfect. Did that myself too before searching in the issue list.

rudiedirkx’s picture

Status: Reviewed & tested by the community » Needs work

Scratch that. The patch doesn't apply correctly, because it's created incorrectly. You've created it from your site folder, not the module folder.

diff --git a/modules/contrib/hierarchical_select/includes/ b/modules/contrib/hierarchical_select/includes/

should be

diff --git a/includes/ b/includes/
Ignigena’s picture

Status: Needs work » Needs review
812 bytes

Fixed the patch provided in #4 and everything should apply correctly.

Tim Jones Toronto’s picture

Status: Needs review » Reviewed & tested by the community

Have tested patch #9 and confirm it works using PHP 5.4.7.


rudiedirkx’s picture

And now someone should tell Wim Leers...

jibran’s picture

Version: 7.x-3.0-alpha5 » 7.x-3.x-dev
Category: task » bug

+1 for RTBC

yannickoo’s picture

Patch from #9 works fine.

ptmkenny’s picture

I was also able to successfully apply the patch in #9, which fixed the error for me.

rudiedirkx’s picture

Status: Reviewed & tested by the community » Needs work

@Ignigena It's kind weird though... Why is there a line

array_merge($element['#attributes']['class'], $classes);

with nothing else on it? It's useless. So I'm gonna have to unapprove.

Anonymous’s picture

Status: Needs work » Reviewed & tested by the community

Seems fine. RTBC +1

@rudiedirkx, it seems that line simply was a mistake. The patch from #9 fixes this.

rudiedirkx’s picture

Status: Reviewed & tested by the community » Needs work

No, it doesn't. That line is still in there and it shouldn't be, because it's useless and confusing.

The patch in #9 (and this issue) is not ready.

rudiedirkx’s picture

Oh wow, I am really blind... Wow!

Sorry guys. =) RTBC indeed!

RobKoberg’s picture

Status: Needs work » Reviewed & tested by the community
843 bytes

The patch in #9 is no longer valid as the line numbers have changed. Attached is a new patch. Why hasn't this been done yet? Seems like an appropriate fix.

kenianbei’s picture

#19 Fixes issue for me as well.

giupenni’s picture

#19 Fixes issue fo me, thank you!

dueron’s picture

30.91 KB

I have also been wrestling with this issue for several days. I get the same unsightly error after turning on PHP 5.4 globally at 1and1 hosting.
I don't wish to revert back to PHP 5.2, and I would like to use this module. Am considering "Simple Hierarchical Select." instead.
I tried the patch in #19, but was not able to make it work with my elementary coding skills. (see attached screenshot)
I would be very grateful if anyone might tell me what I might do to fix this, or help me learn to properly run this patch. Thx!

ptmkenny’s picture

@dueron Documentation on how to apply a patch can be found here:

That said, if you haven't committed to a specific module, at this point in time (early 2013) "Simple Hierarchical Select" is seeing more development activity than this module, so if it does what you want, you might switch to that.

dueron’s picture

@ptmkenny, Thanks for the reference and insight! I did read that instruction article previously, yet was not able to format the patch file properly using bbedit.
Regarding "Simple H S," I have been switching between the two modules with limited success, and trying to decide. I can't seem to make either one work very well when I move from Devel. to Production Host server.

"H S" works GREAT (and looks so nice) in my development environment, using PHP 5.3 or lower. However, when I move it to 1and1 (which only offers the choices: PHP 5.2, 5.4 & "5 dev" Simple HS doesn't even display, when I move to the online server host.

I would like to start using the "Course" module, which requires PHP 5.4. I am slowly learning that learning that Drupal development is constant series of prioritizing choices. (like life, I guess). Thx again!

Taxoman’s picture

Priority: Normal » Major

Any reason this cannot be committed to the -dev branch?

mmilano’s picture

+1 RTBC for #19.

A work around in the mean time for those not wanting to patch would be to override the theme function in your theme's template.php file. I commented in caps the only change to the original.

function MYTHEMENAME_hierarchical_select($variables) {
  $element = $variables['element'];
  $output = '';

  // Update $element['#attributes']['class'].
  if (!isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = array();
  $hsid = $element['hsid']['#value'];
  $level_labels_style = variable_get('hierarchical_select_level_labels_style', 'none');
  $classes = array(
   // Classes that make it possible to override the styling of specific
   // instances of Hierarchical Select, based on either the ID of the form
   // element or the config that it uses.
   'hierarchical-select-wrapper-for-name-' . $element['#id'],
   (isset($element['#config']['config_id'])) ? 'hierarchical-select-wrapper-for-config-' . $element['#config']['config_id'] : NULL,
  array_merge($element['#attributes']['class'], $classes);
  // $element['#attributes']['class'] .= ' ' . implode(' ', $classes);
  $element['#attributes']['class'] += $classes;

  $element['#attributes']['id'] = "hierarchical-select-$hsid-wrapper";
  $element['#id'] = "hierarchical-select-$hsid-wrapper"; // This ensures the label's for attribute is correct.

  return '<div ' . drupal_attributes($element['#attributes']) . '>' . drupal_render_children($element) . '</div>';
dshields’s picture

Patch in #19 solves the problem for me

djroshi’s picture

I can also confirm that #19 fixes the issue

yannickoo’s picture

I applied the patch an re-created it with git diff which looks more like a git patch (looks like #9 now :D ).

mpgeek’s picture

#29 Worked for me. Gracias.

RoSk0’s picture

766 bytes

Patch from #29 works, but code could be prettier $element['#attributes']['class'] += $classes;. Patch attached.
+1 to RTBC.

rudiedirkx’s picture

@RoSk0 That's not how array addition works.

$exist = array('a', 'b');
$add = array('c', 'd');
$exist += $add;

will output [a, b] not [a, b, c, d].

For assoc arrays, that's the wanted behavior. Not for numeric arrays.

RoSk0’s picture

@rudiedirkx thanks for the comment!
That means that patch from #29 is the one to commit.

rv0’s picture

+1 for #29

jorgemontoyab’s picture

# 19 works fine. Thanks

vlad.leo’s picture

Sory patch hierarchical_select-php_54-1587570-29.patch do not solve problem

kingfisher64’s picture

patch #29 works fine.

Any chance of a new release as the latest dev is a year old and reads +9 dev not including any patches to be committed like this.

Wim Leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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