I switched from 2.4 to dev and I get this error. Do not go away even returning to 2.4
warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /home/tuxsaeu/public_html/sites/all/modules/ubercart/uc_catalog/uc_catalog.module on line 888.

Files: 
CommentFileSizeAuthor
#24 888.patch489 bytesTR
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 888.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

Comments

TR’s picture

Status:Active» Postponed (maintainer needs more info)

What were you doing and on what page did you see this warning message? If you don't provide steps to reproduce the error, we can't find it and fix it. Please read http://drupal.org/node/73179

hopfrog’s picture

1. the error appeared after upgrading to version dev.
2. It is present on all pages in http://tuxsa.eu

bobburns’s picture

I see no resolution here, nor was i aware it had been reported.

This is a bug in the dev upgrade - nothing needs to be done to make it happen but install the latest dev version

hopfrog’s picture

OK. Thanks

TR’s picture

@bobburns: Who said there was a resolution? The status is "postponed (maintainer needs more info)", and if more info isn't provided it's going to stay that way. If this was a one-time error that showed up on some unspecified page during an unknown point in the upgrade process, then I don't see any cause for concern. If the warning message continues to show up, then I need know where and when it appears - is it on every page, does it show on some pages only, does it show up in response to a particular action taken on the site? Line 888 hasn't been changed in more than 3 years, and there are no previous reports of this error over the past 3 years.

@hopfrog: I don't see this message when I visit your site.

hopfrog’s picture

I don't know the answer but I just avoided the appearance of the error. In fact, the error is visible when I put the "Catalog" on the sidebar when this block there isn't the error disappears.
On a different installation, however, the problem does not exist. For this reason I believe that comes from something specific for that installation and is not a problem tied directly to Ubercat.

bobburns’s picture

The error shows up on the main page node when a user logs in (admin or user)

There are 8 instances of the same error in a pink box

warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /. . . /modules/ubercart/uc_catalog/uc_catalog.module on line 888.

I have updated to the latest dev build of ubercart (July 13) and it still appears.

I built a new domain Drupal install with a copied Database - the EXACT same database (downloaded gz backup, expanded as text sql file, edited database name and domain name with find and replace, copied ALL drupal files from the exiting site up and over to the new domain, created new database, then installed drupal, then deleted that database and recreated an empty one of the new installed drupal site database name and password, and using phpmyadmin imported the sql file into the new empty database on the new domain) - EVERYTHING came up as the old site under the new domain and the new site DOES NOT show the error.

Only one query did not go into the new database on the new site => this one

/*!50001 CREATE ALGORITHM=UNDEFINED *//*!50013 DEFINER=`database_drpl1`@`localhost` SQL SECURITY DEFINER *//*!50001 VIEW `uc_order_products_pair_vw` AS select `op1`.`nid` AS `nid`,`op2`.`nid` AS `pair_nid`,sum(`op2`.`qty`) AS `pair_sum_qty`,count(`op2`.`nid`) AS `order_count` from (`uc_order_products` `op1` join `uc_order_products` `op2`) where ((`op1`.`order_id` = `op2`.`order_id`) and (`op1`.`nid` <> `op2`.`nid`)) group by `op1`.`nid`,`op2`.`nid` order by `op1`.`nid`,count(`op2`.`nid`) desc,sum(`op2`.`qty`) desc */;

as phpmyadmin claimed super user privileges were necessary for the query to complete --- but other than that the databases were identical and the new site does not show the error - while the other site still does

TR’s picture

That query is from the uc_views module, and yes you do need super user privileges in your database for that. You can search the uc_views issue queue to find out more about that problem. I'm not sure if that's what's causing the error here, but you could always try disabling uc_views to see if the problem goes away.

bobburns’s picture

No, disabling uc_views did not end the error

bobburns’s picture

This error persists after two new dev upgrades - can someone tell me how to fix it?

didumir’s picture

Maybe it is depending on the version of PHP in use?

The error shows up here when creating new products. After reading http://php.net/manual/en/function.array-key-exists.php
(This function doesn't work with objects anymore, property_exists() should be used in this case.)
I changed the call to "property_exists" and now it seems to work...

TR’s picture

@didumir: Interesting. I'm using PHP 5.2.13, so if PHP version is the problem that explains why I don't see it.

@bobburns, @hopfrog: Are you using PHP 5.3?

FYI, Drupal core does not run properly on PHP 5.3 yet ... there are several hundred issues in the core issue queue about the problems.

bobburns’s picture

I am running php 5.2.17

This error is beginning to show up on websites around the web - I found it here => http://www.thisisaustralia.com.au/ in public display

bobburns’s picture

didumir -- thanks see below (I retracted the comment that was here asking for code snippet)

bobburns’s picture

See didumir's post number 11 . . .

in the ubercart/uc_catalog/uc_catalog.module text file there is only one "array_key_exists" function call

// Determine whether to expand menu item.
if ((arg(0) == 'node' && array_key_exists ($branch->tid, $terms))) {
$inpath = FALSE;

which I changed to

// Determine whether to expand menu item.
if ((arg(0) == 'node' && property_exists ($branch->tid, $terms))) {
$inpath = FALSE;

Made my error go away - don't know if the create products and the such will work however - have not tested it. Right now at this very instant I will settle for the error gone from public display on the website.

I fixed it on the July 17th dev build, - then the July 18th dev build was posted and when I installed the July 18th dev build - the error returned again; and, the array_key_exists function call was still in there - so at least I knew where to go to "fix" it.

Now I am going to try to add some new products and see what happens

longwave’s picture

Title:Error on line 888» array_key_exists(): The second argument should be either an array or an object in uc_catalog.module on line 888

Improving title.

sah62’s picture

Subscribing - I'm seeing this error in my log multiple times when creating a new product. I'm using PHP 5.2.14.

bobburns’s picture

Title:array_key_exists(): The second argument should be either an array or an object in uc_catalog.module on line 888» Error on line 888
Version:6.x-2.x-dev» 7.x-3.0-alpha1

sah62 - is that before or after trying the work-around fix?

TR’s picture

Title:Error on line 888» array_key_exists(): The second argument should be either an array or an object in uc_catalog.module on line 888
Version:7.x-3.0-alpha1» 6.x-2.x-dev
franklca’s picture

The fix in #15 corrected this error for me in Drupal 6.22.

sah62’s picture

It's before trying the fix. Some more info:

I just got 22 entries in my log after hitting the "Create content" (node/add) link. I, too, display my product catalog in a block on my front page, and there just happens to be 22 menu items in the catalog. I haven't tried the fix because the error isn't visible to my customers and it's a bit of a pain to have to re-patch after every new dev release. I can live with the error in my log until a fix is committed.

TR’s picture

[function.array-key-exists]: The second argument should be either an array or an object means that in the function call array_key_exists ($branch->tid, $terms), $terms is not an array or an object. It's probably NULL. Regardless, because $terms is not the correct type array_key_exists() will return FALSE and print this error.

Substituting property_exists ($branch->tid, $terms) is clearly wrong because property_exists() takes a class or an object as the first argument and a string as the second argument. $branch->tid is NOT a class or an object, it's an integer, and $terms, as we know from above, is probably NULL. The only thing you're doing here is substituting a function (property_exists()) that doesn't print an error when you give it wrong arguments. It instead returns NULL. You're still giving it wrong arguments, you're just not seeing any visible sign of an error. Even if you switched the order of the arguments to properly call property_exists(), we're left with the problem that $terms is still not an object so property_exists() will still return NULL.

The question that needs to be answered is why is $terms not an array or object at this point, when it is for the majority of Ubercart users. That's something that has to be debugged by a person who's experiencing the problem (which I'm not).

sah62’s picture

Here's what I can see, TR. Here's the code in question:

  if (!isset($terms)) {
    $node = menu_get_object('node', 1);
    if (isset($node)) {
      $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    }
  }

isset($node) is returning FALSE for me, and so $terms is not assigned a value before array_key_exists() is called. Is there something else I can debug more deeply?

TR’s picture

Category:support» bug
Status:Postponed (maintainer needs more info)» Needs review
StatusFileSize
new489 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 888.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

OK, that explains why this error started showing up all of a sudden. Those lines were added just a few weeks ago, in commit cce93c58. Before the commit, that section of code was just:

  if (!isset($terms)) {
    $terms = taxonomy_node_get_terms_by_vocabulary(menu_get_object('node', 1),  $vid);
  }

This would generate a PHP notice if menu_get_object('node', 1) didn't return an object, but $terms would be set to be an empty array(), which doesn't cause an error when used in array_key_exists() later on. The PHP notice was invisible, because Drupal 6 disables PHP notice reporting by default.

In the changed version, the same thing happens: menu_get_object('node', 1) doesn't return an object, so $node isn't set, but now $terms never gets a value at all. The changed version avoids the invisible PHP notice but now triggers a visible PHP warning because $terms = NULL is passed to array_key_exists() instead of $terms = array() as before.

So to make it behave exactly the same way as before the above lines were changed, all you should have to do is apply the attached patch.

If I can get some confirmation that this patch works I'll commit it.

longwave’s picture

It's a similar approach to 7.x so I think it should be fine.

http://drupalcode.org/project/ubercart.git/blob/refs/heads/7.x-3.x:/uc_c...

sah62’s picture

The patch works for me - no more log entries. Thanks, TR!

TR’s picture

@bobburns, @hopfrog: Does the patch fix the issue for you?

longwave’s picture

Status:Needs review» Fixed

Committed #24.

Status:Fixed» Closed (fixed)

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