Hi, this is already reported in others modules too #326041: Fatal error: Unsupported operand types in:, but in my case is happening in system.module. Some hosting sites, using PHP 5.2.6 (like Mosso) are rising this problem. Can't array_merge be used as default in core modules in order to avoid this?

Comments

sfranchi’s picture

This error only happens when the array to be added is not actually an array (as when db_fetch_array() returns FALSE).
The array can be avoided by casting the element to add as an array using

$data += (array)$otherdata;

but anyway, the code using this should be able to take action based on that.

gábor hojtsy’s picture

Status: Active » Closed (works as designed)

The modules reusing core functions should ensure that data passed in is an array, not FALSE, when the API documents to accept an array and no non-arrays. Please reopen this if you know of core places where the data type is not checked or documented in the API when expecting an array.

sfranchi’s picture

Ok, but the core shouldn't check the received data? A simple call to is_array will make it bullet (and fool) proof.

gábor hojtsy’s picture

Drupal does not usually check data type to be the one defined by the API, except when there is some security concern. Where exactly would you think we'd need this?

damien tournoud’s picture

We don't babysit broken code. That create cruft everywhere.

In Drupal 7, now that we require PHP5, we are adding type-hinting to those types of parameters.

sfranchi’s picture

Where ? Wherever it can cause a crash, but if you think is only responsability of the module consuming the API, is ok the way it is, there is nothing to change.

# Damein, good to hear that about Drupal 7.

Thanks,