Unsupported Operand Types in Code

dman - July 2, 2006 - 22:13
Project:Import / Export API
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

... I know this is totally volatile, but trying to have a look at some of the concepts, I found problems as I didn't have 'profile' or 'location' enabled.
I therefore filter out unused entity definitions, and added some warning messages if anything else is unstable.

.. and WTF was $array1 += $array2 ?
( $field += $default_values; )
Didn't work on my PHP5, so I replaced it with array_merge.

I'm impressed (and intimidated by) the general-case field definitions and value mapping engine.
Still trying to figure out what the public interface hooks are - what are the most common functions I'm expected to be calling from another module to get things happening? Eg, I have a data structure I want to hand to import. ... what's step 1?

.dan.

AttachmentSize
robustness_fix_for_missing_modules.patch.txt1.95 KB

#1

Jaza - July 3, 2006 - 00:01
Category:bug report» support request

Correct - although the API is already working and is somewhat stable (i.e. it's not particularly volatile), it is still in the alpha stage, and is for developer consumption only.

Thanks for pointing out that $arr1 += $arr2 sometimes doesn't work in PHP5 - extra testing is always appreciated, as I do all of my development in a PHP4 environment. However, the array union operator should work for you - AFAIK (i.e. according to the manual), it works the same in PHP5 as in PHP4. Anyway, I'll try array_merge instead.

The warnings look good - except that I'm trying to avoid using things like drupal_set_message() directly within the API functions. This is because drupal_set_message() and friends (e.g. form_set_error) assume that the operation is being run through a UI, whereas it might actually be running from a cron job, from a command-line script, etc. Instead, I'll be looking at returning error codes, and then leaving the mapping of these codes into human-readable messages as something for a higher layer to handle.

Note that the current 'UI' (i.e. the 'import' and 'export' pages) is for dev and testing purposes only (hell, it even relies on the devel module!).

#2

dman - July 3, 2006 - 00:14

That manual page didn't specifically mention "+=" which is what I was quickly scanning for, but I guess support is implied.
If it is legal syntax (I'd just not seen it used in PHP before) maybe my error was because one of the values was not an array. Usually I get an "incorrect parameter" error in this case, but I got "Unknown operand" instead.
$null_value += $array1 is what failed.

I know that it's not the place for user errors - like I said, I just threw it in to alert me about what might be broken. In theory code should NEVER get to those points, right.
I did so because I was trying to see what was wrong after I CVS 'updated' my copy ... which missed your new subdirectory with the engines :-)
cvs update -d
fixed the problem as soon as I saw the message. Uncommon mistake maybe, but I always try to be verbose.

.dan.

#3

stella - July 24, 2006 - 12:21

I also decided to try out the latest CVS verison of this module and got a similar error:

Fatal error: Unsupported operand types in /var/www/crafts.stellapower.net/modules/importexportapi/importexportapi.module on line 242

This is happening with php 4.3.10-16 with apache2 on a debian-sarge box.

Keep up the good work.

Cheers,
Stella

#4

Jaza - August 27, 2006 - 14:53
Status:active» closed

This bug no longer exists, since there is now the importexportui module, which only allows you to run an import or export on entities for which both (a) the defining module is enabled, and (b) a definition is available.

#5

treytabner - July 26, 2007 - 06:24
Category:support request» bug report
Status:closed» active

Actually, I am using the latest release (5.x-1.1) with PHP5, and I'm getting the $field += $default_values; problem... += is crashing PHP causing blank pages. I changed the line 244 of importexportapi.module from:

$field += $default_values;

to

$field = array_merge($field, $default_values);

And now I can export data. Before it was just a blank, crashed page.

#6

sun - December 7, 2007 - 18:16
Version:HEAD» 5.x-1.x-dev
Status:active» needs review

So why not patch it?

AttachmentSize
importexportapi.array-merge.patch 1.71 KB

#7

sun - December 7, 2007 - 18:31
Title:Problem if optional modules are not installed» Unsupported Operand Types in Code

#8

cha0s - July 7, 2009 - 07:16

From what I've seen, the operand error is the result of the lhs of the expression not being an array (usually NULL). Properly initializing our variables is the correct solution, and I'll get a patch up for it.

#9

earnie - July 7, 2009 - 14:25
Status:needs review» needs work

Thanks cha0s. @sun: Is array_merge the same as +=? I know Drupal core uses += often and the first time I saw it was perplexed by it.

Answering my own question array_merge will replace duplicate keys with the value of the second while += will not replace the value of the duplicate key from the first. So to use array_merge to do the same as += you need the left hand array to be in the second argument of the array_merge function.

http://us3.php.net/array_merge
http://us3.php.net/manual/en/language.operators.array.php

Note PHP 5 changed the argument requirements for array_merge to be explicitly an array type. So the patch may simply be something similar to the following.

<?php
 
(array)$field += (array)$default_values;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.