Jump to content

Upgrade to 6.4.3 now getting this error


Recommended Posts

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

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

Posted (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 by bsmither
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 (!==).

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Posted (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 by bsmither
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Posted (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 by bsmither
Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...