Claudia M Posted June 1, 2021 Share Posted June 1, 2021 I upgraded to 6.4.3. now I have over 80 of these errors in my log [01-Jun-2021 10:30:03 America/Louisville] PHP Warning: Division by zero in /home/xxxxx/public_html/classes/cubecart.class.php on line 126 [01-Jun-2021 10:32:36 America/Louisville] PHP Warning: Division by zero in /home/xxxxx/public_html/classes/cubecart.class.php on line 126 [01-Jun-2021 11:00:03 America/Louisville] PHP Warning: Division by zero in /home/xxxxx/public_html/classes/cubecart.class.php on line 126 [01-Jun-2021 11:12:20 America/Louisville] PHP Warning: Division by zero in /home/xxxxx/public_html/classes/cubecart.class.php on line 126 I also got these errors but not sure if it's related to 6.4.3 [31-May-2021 21:28:32 America/Louisville] PHP Warning: Invalid argument supplied for foreach() in /home/xxxxx/public_html/classes/tax.class.php on line 111 [31-May-2021 21:28:32 America/Louisville] PHP Warning: Invalid argument supplied for foreach() in /home/xxxxx/public_html/classes/tax.class.php on line 129 [31-May-2021 17:05:09 America/Louisville] PHP Warning: array_intersect_key() [<a href='http://docs.php.net/manual/en/function.array-intersect-key.php'>function.array-intersect-key.php</a>]: Expected parameter 2 to be an array, null given in /home/xxxxx/public_html/modules/plugins/Show_Inventory_on_Orders_List/hooks/admin.reports.order.post.php on line 10 Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 1, 2021 Share Posted June 1, 2021 Upgraded to CC643 from what version? On a stock cubecart.class.php file, line 126 calculates the average score from all scores rated against a product. But, this section of code has not changed since CC629 (the latest version checked). Did you also, perchance, also upgrade the version of PHP your server environment is using? Quote Link to comment Share on other sites More sharing options...
Claudia M Posted June 1, 2021 Author Share Posted June 1, 2021 From 642. I don't think my php changed. Still at 7.4.19 I don't use reviews if that helps Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 1, 2021 Share Posted June 1, 2021 (edited) Strange. These "divide by zero" errors should have been seen in prior versions - if the environment did not change (PHP version, database version, etc). As an experiment: In /classes/cubecart.class.php, near lines 125-127, find: if ($product_review[0]['Score'] !== "") { $product['review_score'] = round($product_review[0]['Score']/$product_review[0]['Count'], 1); } Change to: if (!empty($product_review[0]['Count'])) { $product['review_score'] = round($product_review[0]['Score']/$product_review[0]['Count'], 1); } This change gets away from testing for a zero-length string for the summation of all approved review scores*, to testing for the number of approved reviews. * The database's SQL SUM() function should never return a zero-length string, but could return the string "0" if rows were found, null if no rows were found. Edited June 1, 2021 by bsmither Quote Link to comment Share on other sites More sharing options...
Claudia M Posted June 1, 2021 Author Share Posted June 1, 2021 I changed the code. I'll let you know if I see the error again Quote Link to comment Share on other sites More sharing options...
havenswift-hosting Posted June 2, 2021 Share Posted June 2, 2021 23 hours ago, bsmither said: Strange. These "divide by zero" errors should have been seen in prior versions - if the environment did not change (PHP version, database version, etc). These occur under PHP 7.4.X but haven't seen them previously under 7.3.X - can confirm that your changes to cubecart.class.php fixes that problem. I am also seeing the same two errors in tax.class.php also only under PHP 7.4.X Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 2, 2021 Share Posted June 2, 2021 Not under PHP 7.3? Then, under PHP 7.3, I would like to know what the variable type is for $product_review[0]['Score'] and $product_review[0]['Count']. If the variable type of $product_review[0]['Score'] is something other than 'string', then the next statement will not execute. If that is the case, yet in PHP 7.4 when the following statement gets executed, that means something has changed regarding the nature of the arguments of the strict comparison (!==). Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 2, 2021 Share Posted June 2, 2021 But the OP says the upgrade went from CC642 to CC643 and that's when the error started. I just can't find what really changed. Unless the level of error reporting changed so that what was not necessarily logged with CC642 does now get logged. Quote Link to comment Share on other sites More sharing options...
havenswift-hosting Posted June 3, 2021 Share Posted June 3, 2021 6 hours ago, bsmither said: But the OP says the upgrade went from CC642 to CC643 and that's when the error started. It isn’t the move from CC6.4.2 to CC6.4.3 that specifically causes this but moving from PHP 7.3.X to PHP 7.4.X The errors with the foreach statement in tax.class.php are exactly the same, PHP related Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 3, 2021 Share Posted June 3, 2021 The OP believes that the PHP version did not change. Quote Link to comment Share on other sites More sharing options...
Claudia M Posted June 3, 2021 Author Share Posted June 3, 2021 11 minutes ago, bsmither said: The OP believes that the PHP version did not change. Unless Ian updated it and I didn't know. I really don't keep track of that info Quote Link to comment Share on other sites More sharing options...
havenswift-hosting Posted June 3, 2021 Share Posted June 3, 2021 The OP didn’t actually say that just that they were on PHP 7.4.x but they are hosted with us and their PHP version has recently changed from 7.3 to 7.4 Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 3, 2021 Share Posted June 3, 2021 (edited) Good to know. In the Tax class, what did change between CC642 and CC643 is that: From: public $_tax_table_applied = false; To: public $_tax_table_applied = array(); Now, line 104 will always be true, but the foreach at line 105 will never process any of the enclosed statements - possibly being an empty array. Thus, $taxes will not be set and PHP complains about lines 111 and 129. In my opinion, this is a consequence of the above change to CC643. That is, PHP 7.3 should also complain about this. If we change line 104: From: if (is_array($this->_tax_table_applied)) { To: if (!empty($this->_tax_table_applied) && is_array($this->_tax_table_applied)) { // Might not need the is_array() test. Edited June 3, 2021 by bsmither Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 3, 2021 Share Posted June 3, 2021 I've made my first examination of this error. CC642 and CC643 use the same database and same version of PHP (7.4). The query (line 124) returned by Database->select() has a difference. CC642: $product_review[0]['Score'] => '' Score-type => 'string' $product_review[0]['Count'] => '0' Count-type => 'string' CC643: $product_review[0]['Score'] => null Score-type => 'NULL' $product_review[0]['Count'] => '0' Count-type => 'string' The Database->select() has only one relevant change: Lines 709-711, from CC642: foreach ($this->_result as $row) { $output[] = $row; } To CC643: $output = $this->_result; An argument was made the foreach loop was simply building $output from $this->_result, row by row (only the one row in this case), but otherwise no (apparent) changes to the array. The next experiment is to see if appending an array element ($row) onto another array ($output) changes the value of that element. Anyway, Count was always zero and that was what should have been tested for. Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 4, 2021 Share Posted June 4, 2021 (edited) Going deeper... The database actually returns null. The code change in Database->select() does not contribute to this issue. The cached query: \cache\f5a93.sql.527d16e5f76df8acb775d134ecca6a54.cache CC642: a:2:{s:4:"time";i:1622758554;s:6:"expire";i:86400;} -- CubeCart Cache Split -- a:1:{i:0;a:2:{s:5:"Score";s:0:"";s:5:"Count";s:1:"0";}} CC643: a:2:{s:4:"time";i:1622757993;s:6:"expire";i:86400;} -- CubeCart Cache Split -- a:1:{i:0;a:2:{s:5:"Score";N;s:5:"Count";s:1:"0";}} Something between Database->_execute() and Cache->write() is changing the data or Cache->write() gets the data serialized. Edited June 4, 2021 by bsmither Quote Link to comment Share on other sites More sharing options...
havenswift-hosting Posted June 4, 2021 Share Posted June 4, 2021 13 hours ago, bsmither said: Thus, $taxes will not be set and PHP complains about lines 111 and 129. In my opinion, this is a consequence of the above change to CC643. That is, PHP 7.3 should also complain about this. If we change line 104: I can confirm that this fixes this issue as well - thanks Brian ! Quote Link to comment Share on other sites More sharing options...
Claudia M Posted June 4, 2021 Author Share Posted June 4, 2021 Should I keep Brian's change in cubecart.class and should I make this change to tax.class Line 104 From: public $_tax_table_applied = false; To: public $_tax_table_applied = array(); Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 4, 2021 Share Posted June 4, 2021 Sorry, I thought I posted this yesterday: This is a consequence of the GitHub issue #2770: "Database use of stripslashes kills nulls". Everything, actually, is proper up until the CubeCart class, line 125: if ($product_review[0]['Score'] !== "") { evaluates to true - because the value written to the cached, serialized query is no longer an empty string. An issue has been posted in the GitHub. Make the change in cubecart.class.php (line 125) and tax.class.php (line 104). Quote Link to comment Share on other sites More sharing options...
Claudia M Posted June 5, 2021 Author Share Posted June 5, 2021 10 hours ago, Claudia M said: public $_tax_table_applied = array(); My line 104 in classes/tax.class looks like this if (is_array($this->_tax_table_applied)) { What line do I change? Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 5, 2021 Share Posted June 5, 2021 Tax class, line 104: From: if (is_array($this->_tax_table_applied)) { To: if (!empty($this->_tax_table_applied) && is_array($this->_tax_table_applied)) { // Might not need the is_array() test. Quote Link to comment Share on other sites More sharing options...
Claudia M Posted June 5, 2021 Author Share Posted June 5, 2021 Thanks Brian ... and Ian Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.