Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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.
Comments
Comment #1
TR CreditAttribution: TR commentedWhat 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
Comment #2
hopfrog CreditAttribution: hopfrog commented1. the error appeared after upgrading to version dev.
2. It is present on all pages in http://tuxsa.eu
Comment #3
bobburns CreditAttribution: bobburns commentedI 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
Comment #4
hopfrog CreditAttribution: hopfrog commentedOK. Thanks
Comment #5
TR CreditAttribution: TR commented@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.
Comment #6
hopfrog CreditAttribution: hopfrog commentedI 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.
Comment #7
bobburns CreditAttribution: bobburns commentedThe 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
Comment #8
TR CreditAttribution: TR commentedThat 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.
Comment #9
bobburns CreditAttribution: bobburns commentedNo, disabling uc_views did not end the error
Comment #10
bobburns CreditAttribution: bobburns commentedThis error persists after two new dev upgrades - can someone tell me how to fix it?
Comment #11
didumir CreditAttribution: didumir commentedMaybe 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...
Comment #12
TR CreditAttribution: TR commented@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.
Comment #13
bobburns CreditAttribution: bobburns commentedI 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
Comment #14
bobburns CreditAttribution: bobburns commenteddidumir -- thanks see below (I retracted the comment that was here asking for code snippet)
Comment #15
bobburns CreditAttribution: bobburns commentedSee 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
Comment #16
longwaveImproving title.
Comment #17
sah62 CreditAttribution: sah62 commentedSubscribing - I'm seeing this error in my log multiple times when creating a new product. I'm using PHP 5.2.14.
Comment #18
bobburns CreditAttribution: bobburns commentedsah62 - is that before or after trying the work-around fix?
Comment #19
TR CreditAttribution: TR commentedComment #20
franklca CreditAttribution: franklca commentedThe fix in #15 corrected this error for me in Drupal 6.22.
Comment #21
sah62 CreditAttribution: sah62 commentedIt'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.
Comment #22
TR CreditAttribution: TR commented[function.array-key-exists]: The second argument should be either an array or an object
means that in the function callarray_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).
Comment #23
sah62 CreditAttribution: sah62 commentedHere's what I can see, TR. Here's the code in question:
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?
Comment #24
TR CreditAttribution: TR commentedOK, 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:
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.
Comment #25
longwaveIt'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...
Comment #26
sah62 CreditAttribution: sah62 commentedThe patch works for me - no more log entries. Thanks, TR!
Comment #27
TR CreditAttribution: TR commented@bobburns, @hopfrog: Does the patch fix the issue for you?
Comment #28
longwaveCommitted #24.